再会
是否可以使用 Primefaces 数据表来显示不可更新的 Postgres 视图的结果,但在 onRowEdit 事件中有自定义代码?会将更改正确地保存到数据库中吗?
还是必须将 Primefaces / JSF 数据表链接到可更新的实体映射才能用于“更新”和显示信息?
我在 .xhtml 文件中有这个:
<p:dataTable id="conf_data_table" var="confRoomBookingDisplay" style="width: auto" rowIndexVar="rowid" editingRow="true"
value="#{conferenceRoomBookingView.conferenceRoomBookingList}" editable="true"
editMode="row" widgetVar="cellBookings">
<f:facet name="header">
Venue Booking
</f:facet>
<p:ajax event="rowEdit" listener="#{conferenceRoomBookingView.onRowEdit}"
update=":create_new_booking:growl"/>
<p:ajax event="rowEditCancel" listener="#{conferenceRoomBookingView.onRowCancel}"
update=":create_new_booking:growl"/>
<p:column headerText="Booking Ref" style="width: 10%; text-align: center">
<p:outputLabel value="#{ConferenceRoomBooking.conferenceRoomBookingAid}"
style="text-align: center"/>
</p:column>
<p:column headerText="Time Slot" style="width: 10%; text-align: center">
<p:outputLabel value="#{ConferenceRoomBooking.timeSlot}" style="text-align: center"/>
</p:column>
<p:column headerText="Booked For" style="width: 15%; alignment: center">
<p:outputLabel value="#{ConferenceRoomBooking.empShortNameSurname}"
style="text-align: left"/>
</p:column>
<p:column headerText="Booking Comment" style="width: 60%; alignment: center">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{ConferenceRoomBooking.conferenceRoomBookingComment}"/>
</f:facet>
<f:facet name="input">
<p:inputText value="#{ConferenceRoomBooking.conferenceRoomBookingComment}"
style="width:98%"/>
</f:facet>
</p:cellEditor>
</p:column>
<p:column style="width: 5%">
<p:rowEditor />
</p:column>
</p:dataTable>
然后在我的 @RequestScoped (javax.enterprise.context.RequestScoped) @Named 支持 bean 上(我也尝试使用 @ViewScoped - org.omnifaces.cdi 注释)。
事件代码如下所示:
public void onRowEdit(RowEditEvent event) {
conferenceRoomBookingAid = (((ConferenceRoomBookingEntity) event.getObject()).getConferenceRoomBookingAid());
String msgEdit = Long.toString(conferenceRoomBookingAid);
FacesMessage msg = new FacesMessage("Booking Edited for Reference ID:", msgEdit);
FacesContext.getCurrentInstance().addMessage(null, msg);
confRoomService.persistComment(How do I get my updated value from the event???);
}
public void onRowCancel(RowEditEvent event) {
conferenceRoomBookingAid = (((ConferenceRoomBookingEntity) event.getObject()).getConferenceRoomBookingAid());
String msgEdit = Long.toString(conferenceRoomBookingAid);
FacesMessage msg = new FacesMessage("Booking Cancelled for Reference ID: ", msgEdit);
FacesContext.getCurrentInstance().addMessage(null, msg);
}
目前注释掉confRoomService.persistComment(How do I get my updated value from the event???);
代码,让我进入一个正确呈现的表格,我可以在其中编辑行。然而问题是我不能用鼠标点击“接受”/“是”勾号,然后按回车键再次清除单元格。
我使用不可更新视图的原因是当前数据库结构使用外键将数据链接到人员,并且使用基本实体将显示外键 id 而不是其值。