0

我的 xhtml 页面。添加功能工作正常。所以转换器工作正常,由于 ViewScope 不工作,我尝试了 SessionScope,它工作正常。

   <p:commandButton id="addOfficeButton"  icon="ui-icon-circle-plus"  oncomplete="AddOfficeDialog.show();"/>        

   <h:form  id="officeform"> 
    <p:growl id="growl" showDetail="true" sticky="true" />   
      <p:dataTable id="officeDT" var="office" value="#{offices}" rowKey="#{office.id}" style="width:40%"
                   selection="#{officeManagementController.selectedOffice}" selectionMode="single" editable="true">
        <p:ajax event="rowSelect" listener="#{officeManagementController.onRowSelect}" oncomplete="editDlg.show()"
                update=":tabView:officeform:growl,:tabView:officeform:editPanel"/> 
        <p:column sortBy="#{office.id}" headerText="Office ID">
            <h:outputText value="#{office.id}" />  
        </p:column>  

        <p:column headerText="System">     
               <h:outputText value="#{office.department.name}" />
        </p:column>  

        <p:column headerText="Section">     
               <h:outputText value="#{office.role.name}" rendered="#{office.role!=null}"/> 
        </p:column>  


        <p:column headerText="Options" style="width:50px"> 
           <p:rowEditor></p:rowEditor>    
        </p:column> 
      </p:dataTable>

      <p:dialog id="AddOfficeDialog" widgetVar="AddOfficeDialog" modal="true" header="Add/Edit Office" hideEffect="fade" showEffect="fade">
        <p:outputPanel layout="block" id="officeDetail">
         <p:panelGrid columns="2">

            <h:outputText value="Systemmm" />  
            <h:selectOneMenu value="#{officeManagementController.selectedSystem}" converter="#{applicationSystemConverter}">  
               <f:selectItem itemLabel="Select One" itemValue="#{null}" />  
               <f:selectItems value="#{departmentss}" var="appdepartment" itemLabel="#{appdepartment.name}" itemValue="#{appdepartment}"/> 
               <f:ajax event="change" listener="#{officeManagementController.onDepartmentChanged}" render="role"/> 
            </h:selectOneMenu> 

            <h:outputText value="Section" />  
            <h:selectOneMenu id="role" validate="true" value="#{officeManagementController.newOffice.role}" converter="#{departmentSectionConverter}">  
               <f:selectItem itemLabel="Select One" itemValue="#{null}" />  
               <f:selectItems value="#{officeManagementController.assignableRoles}" var="role" itemLabel="#{role.name}" itemValue="#{role}"/>  
            </h:selectOneMenu> 


         </p:panelGrid>
         <p:outputPanel layout="block" style="text-align:center;">
            <p:commandButton actionListener="#{officeManagementController.createOffice}" id="addOffice"  
                             value="Add Office" title="Add new office" oncomplete="AddOfficeDialog.hide();" update="growl,officeform"/>  
         </p:outputPanel>
        </p:outputPanel>
      </p:dialog>

       <p:dialog id="editDlg" widgetVar="editDlg" modal="true"  header="Add/Edit Office" hideEffect="fade" showEffect="fade">
       <p:outputPanel  id="editPanel">
         <p:panelGrid columns="2">
          <h:outputLabel value="Office ID: " />
            <h:outputText  value="#{officeManagementController.selectedOffice.id}"/>


            <h:outputText value="System" />  
            <h:selectOneMenu value="#{officeManagementController.selectedOffice.department}" converter="#{applicationSystemConverter}">  
               <f:selectItem itemLabel="Select One" itemValue="#{null}" />  
               <f:selectItems value="#{applicationSystems}" var="appdepartment" itemLabel="#{appdepartment.name}" itemValue="#{appdepartment}"/> 
               <f:ajax event="change" listener="#{officeManagementController.onApplicationSystemChanged}" render="sect"/> 
            </h:selectOneMenu> 

            <h:outputText value="Section" />  
            <h:selectOneMenu id="sect" validate="true" value="#{officeManagementController.selectedOffice.role}" converter="#{departmentSectionConverter}">  
               <f:selectItem itemLabel="Select One" itemValue="#{null}" />  
               <f:selectItems value="#{officeManagementController.assignableSysSections}" var="role" itemLabel="#{role.name}" itemValue="#{role}"/>  
            </h:selectOneMenu> 

           </p:panelGrid>
           <p:outputPanel layout="block" style="text-align:center;">
           <h:inputHidden binding="#{officeManagementController.selectedOfficeId}" />
          <p:commandButton actionListener="#{officeManagementController.updateOffice()}" 
                    value="Update Office" title="Update office" oncomplete="editDlg.hide();" update="@this,editPanel,growl,officeform"/>  
            </p:outputPanel>
         </p:outputPanel>
      </p:dialog>

   </h:form>

支持豆:

    public void updateOffice() {
        selectedOffice.setId(Long.valueOf((String)selectedOfficeId.getValue()));
        officeManagementService.update(selectedOffice);
        facesContext.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, CrudStatusMessage.SUCCESS.toString(), "Successfully updated Module: " + selectedOffice.getName()));
    }

我正在使用行值填充对话框,但问题是单击更新按钮,我在部门上收到值不是有效错误,但主要是未设置 selectedModule 的值。请帮忙。坚持了一周。

4

2 回答 2

0

首先你不需要()

<p:commandButton action="#{officeManagementController.updateOffice}" value="Update Office" title="Update office" oncomplete="editDlg.hide();" update="@this,editPanel,growl,officeform"/>  

尝试<f:ajax/>在你的中使用<h:selectOneMenu>并检查它是否有效。

于 2013-02-01T03:54:43.023 回答
0

我认为您实际上需要actionListener(而不是action)按钮。您应该阅读 API 文档中的差异,但底线是 actionListener 将执行 AJAX 回发,而 action 将导致重定向(这反过来会破坏您的视图并将其替换为新视图)。

于 2013-01-31T23:40:32.567 回答