0

我有一个显示部门名称和角色名称的 Office 数据表。部门和角色是对象。当我选择rowedit时,当部门发生变化时,应该重新加载角色。我不确定如何通过所选部门并重新呈现角色。

<p:column headerText="Department">     
   <p:cellEditor>  
       <f:facet name="output"><h:outputText value="#{office.department.name}" /></f:facet>  
       <f:facet name="input">
         <p:selectOneMenu value="#{office.department}" converter="#{departmentConverter}" style="width:96%" >   
           <f:selectItems value="#{departments}" var="dept" itemLabel="#{dept.name}" itemValue="#{dept}"/>  
           <p:ajax event="change"  listener="#{officeManagmentController.onDepartmentChanged()}"/>
         </p:selectOneMenu>
       </f:facet>
   </p:cellEditor> 
</p:column>  

<p:column headerText="Role">     
   <p:cellEditor>  
       <f:facet name="output"><h:outputText value="#{office.role.name}" /></f:facet>  
       <f:facet name="input">
         <p:selectOneMenu value="#{office.role}" converter="#{roleConverter}" style="width:96%" >   
           <f:selectItems value="#{officeManagementController.assignableRoles}" var="role" itemLabel="#{role.name}" itemValue="#{role}"/>  
         </p:selectOneMenu>
       </f:facet>
   </p:cellEditor> 
</p:column>  

以下是我的officecontroller managedbean

@ConversationScoped

public class OfficeManagementController implements Serializable {

    public void onRowSelect(SelectEvent event) {  
        FacesMessage msg = new FacesMessage(selectedOffice.getName()+" selected"); 
        selectedDepartment=selectedOffice.getDepartment();
        FacesContext.getCurrentInstance().addMessage(null, msg);  
    }  


    public void onDepartmentChanged() {

        if(selectedOffice!=null)selectedSystem=selectedOffice.getDepartment();
        log.info("Calling onDepartmentChanged " + ((selectedDepartment != null) ? selectedDepartment.getName() : "null"));
        if(selectedDepartment != null) {
            assignableRoles = roleRepo.findByDepartment(selectedDepartment);
            for(int i=0;i<assignableRoles.size();i++){
                System.out.println(assignableRoles.get(i));
            }

        } else {
            assignableRoles=null;
        }
    }
}

我注意到在 onDepartmentChanged() 方法中 selectedOffice 为 null,但在 onrowselect 中,该值不为 null。我没有比这更进一步。当部门发生变化时,我必须动态地改变角色。为什么 selectedOffice 为空?

4

0 回答 0