0

我正在使用 Mojarra、PF 3.5 SNAPSHOT、Tomcat 7.0.32 并尝试在其他客户端完成更改时自行更新数据表。我还将 CDF bean 与 MyCODI、@ViewAccessScoped 一起使用。

当我使用 3.4 时,行内编辑(而不是单元格内编辑)和标准 @ConversationScoped 它正在工作。

这是xhtml:

<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:f="http://java.sun.com/jsf/core"
  xmlns:fn="http://java.sun.com/jsp/jstl/functions"
  xmlns:ui="http://java.sun.com/jsf/facelets"
  xmlns:p="http://primefaces.org/ui"
  xmlns:pe="http://primefaces.org/ui/extensions"
  xmlns:c="http://java.sun.com/jsp/jstl/core"
  xmlns:t="http://myfaces.apache.org/tomahawk">  

<ui:composition template="commonLayout.xhtml">                    

    <ui:define name="content">

        <p:growl id="growlmessage" showDetail="false" autoUpdate="true"/> 

        <p:contextMenu for="staffTable">  
            <p:menuitem value="Open" update="staffTable" icon="ui-icon-close" actionListener="#{staffbean.onOpen}" />  
            <p:menuitem value="Delete" update="staffTable" icon="ui-icon-close" onclick="confirmation.show()" />
        </p:contextMenu>  

        <p:confirmDialog id="confirmDialog" message="#{text['viewedit.delete.confirm']}"  
                         header="#{text['viewedit.delete.header']}" severity="alert" widgetVar="confirmation" appendToBody="true" closable="false" visible="false" >  
            <p:commandButton action="#{staffbean.onDelete}" ajax="true" value="Yes"  oncomplete="confirmation.hide()" icon="ui-icon-check" /> 
            <p:commandButton value="No" onclick="confirmation.hide()" type="button" icon="ui-icon-closethick" />   
        </p:confirmDialog>              

            <p:dataTable id="staffTable" var="staff" widgetVar="staffList" value="#{staffbean.objectList}" paginator="true" rows="15" paginatorPosition="bottom" paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}" currentPageReportTemplate="#{text['table.staff.filter.count']}" rowsPerPageTemplate="15,25,50,100" emptyMessage="#{text['table.staff.filter.notfound']}" filteredValue="#{staffbean.filteredObject}" editable="true" editMode="cell" draggableColumns="true" rowKey="#{staff.id}" selection="#{staffbean.selectedObject}" selectionMode="single"> 

                <f:facet name="header">                    
                    <p:columnGroup type="header">
                        <p:row>
                            <p:column colspan="4">
                                <h:outputText value="#{text['table.staff.header']}" />    
                            </p:column>
                        </p:row>
                        <p:separator/>
                        <p:row>
                            <p:panelGrid columns="5" styleClass="headerGrid">
                                <p:column colspan="2">
                                    <h:outputText value="#{text['table.filter.global']}" />                                    
                                    <p:inputText id="globalFilter" onkeyup="staffList.filter()" style="width:150px" />                                                             
                                </p:column>
                                <p:column colspan="2">
                                    <p:selectOneMenu id="pageonly" value="#{staffbean.pageOnly}" >                                         
                                        <f:selectItem itemLabel="#{text['dataexporter.pageonly']}" itemValue="true" />  
                                        <f:selectItem itemLabel="#{text['dataexporter.entirepage']}" itemValue="false"  /> 
                                        <p:ajax event="change" listener="#{staffbean.exportXLS}" update="@form" immediate="true" />
                                    </p:selectOneMenu>                                                     
                                    <h:commandLink>  
                                        <p:graphicImage id="exportPage" value="/resources/img/excel.png" />  
                                        <p:dataExporter type="xls" target="staffTable" fileName="staff" pageOnly="#{staffbean.pageOnly}"/>  
                                        <p:tooltip for="exportPage" value="#{text['dataexporter.tooltip']}" showEffect="fade" hideEffect="fade" />  
                                    </h:commandLink>                              
                                </p:column>
                            </p:panelGrid>
                        </p:row>
                    </p:columnGroup>                  
                </f:facet>

                <p:column id="nameColumn" headerText="#{text['label.name']}" sortBy="#{staff.name}" filterBy="#{staff.name}" filterMatchMode="contains">
                    <p:cellEditor>  
                        <f:facet id="nameoutput" name="output">  
                            <h:outputText value="#{staff.name}" /> 
                        </f:facet> 
                        <f:facet name="input">  
                            <p:inputText value="#{staff.name}" style="width:100%" required="true" requiredMessage="#{text['validation.error.required.name']}"/>  
                        </f:facet> 
                    </p:cellEditor>
                </p:column>  

                <p:column id="staffnoColumn" headerText="#{text['label.staffno']}" sortBy="#{staff.staffno}" filterBy="#{staff.staffno}" filterMatchMode="contains">  
                    <p:cellEditor>  
                        <f:facet name="output">  
                            <h:outputText value="#{staff.staffno}" /> 
                        </f:facet> 
                        <f:facet id="staffliststaffno" name="input">  
                            <p:inputText value="#{staff.staffno}" style="width:100%" required="true" requiredMessage="#{text['validation.error.required.staffno']}">                              
                                <pe:keyFilter regEx="/^\d+$/" preventPaste="false"/>                            
                                <f:validator validatorId="staffnoValidator" />   
                                <f:validator validatorId="numericValidator" /> 
                            </p:inputText>
                        </f:facet> 
                    </p:cellEditor> 
                </p:column>          

                <f:facet name="footer" id="footer">  
                    There are #{fn:length(staffbean.objectList)} staff in total.  
                </f:facet>                      

                <p:ajax event="cellEdit" listener="#{staffbean.onEdit}" update="@form" />                

            </p:dataTable>  

    </ui:define>
    <ui:define name="socket">
        <p:socket channel="/ba" >
            <p:ajax event="message" update="ba_staffTable" />
        </p:socket>                          
    </ui:define>       
</ui:composition> 

豆:

      public void update(Object object) {
    if (!getEm().getTransaction().isActive()) {
        getEm().getTransaction().begin();
    }
    try {
        get().merge(object);
        get().getTransaction().commit();
    } catch (PersistenceException e) {
        if (ExceptionUtil.is(e, ConstraintViolationException.class) || ExceptionUtil.is(e, RollbackException.class)) {
            e.printStackTrace();
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, ResourceLoader.MESSAGES.getProperty("staff.error.dbconstraint"), null));
            if (getEm().getTransaction().isActive()) {
                getEm().getTransaction().rollback();
            }
        }
    }
    PushContextFactory.getDefault().getPushContext().push("/ba", "");
}
4

1 回答 1

0

您的表 idstaffTable不是ba_staffTable

于 2013-02-13T02:16:02.537 回答