我有一个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为空?