如果我有一个panelMenu组件,并且它的某些子菜单组件由于其所有子组件的渲染属性设置为false而不显示子组件。如何隐藏子菜单选项?
例如,应隐藏SubMenu_1_2和SubMenu_1_3:
<p:panelMenu>
<p:submenu label="SubMenu_1_1">
<p:menuitem action="#{backingBean.view_1_1_1}" value="View_1_1_1" rendered="true" />
<p:menuitem action="#{backingBean.view_1_1_1}" value="View_1_1_2" rendered="true" />
</p:submenu>
<p:submenu label="SubMenu_1_2">
<p:menuitem action="#{backingBean.view_1_2_1}" value="View_1_2_1" rendered="false" />
</p:submenu>
<p:submenu label="SubMenu_1_3">
<p:menuitem action="#{backingBean.view_1_3_1}" value="View_1_3_1" rendered="false" />
<p:menuitem action="#{backingBean.view_1_3_2}" value="View_1_3_2" rendered="false" />
<p:menuitem action="#{backingBean.view_1_3_3}" value="View_1_3_3" rendered="false" />
</p:submenu>
</p:panelMenu>
如果我需要使用jQuery无关紧要
答案 0 :(得分:0)
步骤1.将id属性提供给panelMenu。
步骤2现在从树中找到该组件,并在存在子项时将呈现的属性设置为false。
<p:panelMenu id="panelMenu">
for(UIComponent component: FacesContext.getCurrentInstance().getViewRoot().getChildren()) {
if(component.getId().contains("panelMenu")){
for(UIComponent panelMenuChild:component.getChildren()){//this is the child of panelMenu ie Submenu
if(panelMenuChild.getChildren().size()>0){
((SubMenu)panelMenuChild).setRendered(false);
}
}
}
}
RequestContext.getCurrentInstance().update("panelMenu");
步骤3.然后更新panelMenu;