Jsf 展开或折叠所有子菜单,无论是全部还是部分子菜单已展开或折叠
目标: 我们要求有一个展开/折叠按钮来展开或折叠所有子菜单-除非其中一个状态不同,否则这似乎是可行的 例如: 菜单状态:true(展开)、true(展开)、true(展开)、true(展开)、true(展开)将在当前代码中更改为false(折叠)、false(折叠)、false(折叠)、false(折叠),反之亦然 但是->true(展开)、false(折叠),true(展开)、true(展开)不会在当前代码中更改为false(折叠)、false(折叠)、false(折叠)、false(折叠),反之亦然 问题: 我有一个问题,视图(xhtml)页面似乎没有更新JSF支持bean 代码: xhtml:Jsf 展开或折叠所有子菜单,无论是全部还是部分子菜单已展开或折叠,jsf,primefaces,submenu,Jsf,Primefaces,Submenu,目标: 我们要求有一个展开/折叠按钮来展开或折叠所有子菜单-除非其中一个状态不同,否则这似乎是可行的 例如: 菜单状态:true(展开)、true(展开)、true(展开)、true(展开)、true(展开)将在当前代码中更改为false(折叠)、false(折叠)、false(折叠)、false(折叠),反之亦然 但是->true(展开)、false(折叠),true(展开)、true(展开)不会在当前代码中更改为false(折叠)、false(折叠)、false(折叠)、false(折叠),
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui" >
<h:head>
<title>Website</title>
</h:head>
<h:body>
<p:growl id="messages"/>
<p:layout id="fullpagelayout" fullPage="true" >
<p:layoutUnit id="layoutNorth" position="north" resizable="true" size="120" style="min-height: 120px; height: 120px;" >
<ui:include id="northHeader" src="header.xhtml" />
</p:layoutUnit>
<p:layoutUnit id="layoutWest" position="west" collapsible="true" resizable="true" style="min-width: 150px;">
<h:form id="menuForm">
<p:commandButton id="expandBtn" value="Expand" action="#{mainMenuBean.changeMenuState(true)}" async="true" update="menuForm:mainMenu" styleClass="expandCollapseBtn" style="margin-bottom: 2px;" />
<p:commandButton id="collapseBtn" value="Collapse" action="#{mainMenuBean.changeMenuState(false)}" async="true" update="menuForm:mainMenu" styleClass="expandCollapseBtn" style="margin-bottom: 2px;" />
<p:panelMenu id="mainMenu" model="#{mainMenuBean.model}" />
</h:form>
</p:layoutUnit>
<p:layoutUnit id="layoutCenter" position="center" style="padding: 5px; margin: 5px;" >
<ui:include id="centerPanel" src="centerPanel.xhtml" />
</p:layoutUnit>
<p:layoutUnit id="layoutSouth" position="south" resizable="true" closable="true" size="30" >
<ui:include id="southPanel" src="status.xhtml" />
</p:layoutUnit>
</p:layout>
</h:body>
</html>
因此,本质上我希望“展开”或“折叠”按钮可以展开或折叠所有子菜单,而不管是全部还是部分子菜单已经展开或折叠
希望这有意义
package /*PACKAGE*/
/*imports*/
@ManagedBean
@SessionScoped
public class MainMenuBean implements Serializable {
private MenuModel model;
private MenuStateController stateController;
private String updateParam;
public MainMenuBean() {
initBeans();
}
private void initBeans() {
buildMainMenu();
}
public MenuModel getModel() {
return model;
}
public void setModel(MenuModel model) {
this.model = model;
}
public void buildMainMenu() {
model = new DefaultMenuModel();
stateController = new MenuStateController();
updateParam = ":panelContents";
// File Submenu and menu Items
DefaultSubMenu fileSubMenu = new DefaultSubMenu("File");
addMenuItem(fileSubMenu, "Logout", "logoutPage", "ui-icon-home",
"/login/login.xhtml?faces-redirect=true", false, false, updateParam, stateController);
model.addElement(fileSubMenu);
// Tools Submenu and menu Items
DefaultSubMenu toolsSubMenu = new DefaultSubMenu("Tools");
addMenuItem(toolsSubMenu, "Tool Page", "toolPage", "ui-icon-wrench",
"#{menuStateController.setPage('/content/tool.xhtml')}", true, true, updateParam, stateController);
model.addElement(toolsSubMenu);
// Search Submenu and menu Items
DefaultSubMenu searchSubMenu = new DefaultSubMenu("Search");
addMenuItem(searchSubMenu, "Search", "searchPage", "ui-icon-search",
"#{menuStateController.setPage('/content/search.xhtml')}", true, true, updateParam, stateController);
model.addElement(searchSubMenu);
// Help Submenu and menu Items
DefaultSubMenu helpSubMenu = new DefaultSubMenu("Help");
addMenuItem(helpSubMenu, "About", "aboutPage", "ui-icon-help",
"#{menuStateController.setPage('/content/about.xhtml')}", true, true, updateParam, stateController);
model.addElement(helpSubMenu);
}
private void addMenuItem(DefaultSubMenu subMenu, String menuItemName, String id, String icon,
String commandName, boolean isAjax, boolean isAsync, String Update, MenuStateController stateController) {
NEWMenuItem item = new NEWMenuItem(menuItemName, id, stateController);
item.setId(id);
item.setIcon(icon);
item.setCommand(commandName);
item.setAjax(isAjax);
item.setAsync(isAsync);
item.setUpdate(Update);
subMenu.addElement(item);
}
public void changeMenuState(boolean expanded) {
for (MenuElement menuElement : model.getElements()) {
if(menuElement.getClass() == DefaultSubMenu.class){
if(menuElement instanceof DefaultSubMenu){
DefaultSubMenu subMenu = (DefaultSubMenu) menuElement;
if(!subMenu.isExpanded() == expanded){
subMenu.setExpanded(expanded);
}
}
}
}
}
}