繁体   English   中英

Primefaces数据表用于显示不可更新的数据库视图结果吗?

[英]Primefaces datatable used to display non updateable database view results?

美好的一天

是否有可能(我似乎被困在无法单击'tick'接受行编辑)来使用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???); 代码,将我带到一个正确呈现的表中,可以在其中编辑行。 但是,问题是我无法用鼠标单击“接受” /“是”对勾,然后按Enter只是再次清除该单元格。

我使用不可更新视图的原因是当前的数据库结构使用外键将数据链接到人员,并且使用基本实体将显示外键id而不是其值。

经过大量不同版本的Entities和数据库视图之后,我得出的结论是应该使用JSF / Primefaces数据表组件:

  1. 当通过可变实体直接链接,从而以100%表示基础数据库表的形式(没有数据的自定义视图)进行链接时,将允许进行完全编辑,并按公布的方式进行工作。
  2. 当链接到基于数据库视图的实体(可更新或不可更新)时,不能在数据表cellEdit或rowEdit事件中编辑数据表的单元格/行。

如果在上面证明是错误的话,我会欣喜若狂,但是现在,在基于数据库视图的情况下,将数据表作为不可变的使用已使人安心。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM