我在我的项目中使用JSF 2.1。我动态创建了菜单。当我使用menuBar
时,它会有效但当我将其更改为tieredMenu
时会出错:
组件库http://primefaces.org/ui不包含此类组件
我的xhtml代码如下:
<p:layoutUnit position="west" size="300" header="Hide me" resizable="false" closable="false" collapsible="true" style="font-weight: bold; width: 500px;">
<h:form >
<p:tieredMenu model="#{menuCreator.model}" style="font-size: 14px; font-weight: bold; color: #000000; position: absolute;"/>
</h:form>
</p:layoutUnit>
我的后端bean在下面:
public MenuCreator() {
model = new DefaultMenuModel();
Gateway_RoleDetail gwRoleDetail = new Gateway_RoleDetail();
List<RoleDetail> lstRoleDetail = new ArrayList<RoleDetail>();
// List<RoleDetail> lstRoleDetail2 = new ArrayList<RoleDetail>();
FacesContext facesContext = FacesContext.getCurrentInstance();
Logininfo logininfo = (Logininfo) facesContext.getApplication().createValueBinding("#{logininfo}").getValue(facesContext);
lstRoleDetail = gwRoleDetail.getRoleDetail(logininfo.getUserType());
Iterator itrRole = lstRoleDetail.iterator();
RoleDetail roleDetail, roleDetailInter,roleDetailsubMenu;
String group_name = "";
String rolename = "";
while (itrRole.hasNext()) {
roleDetail = (RoleDetail) itrRole.next();
if (!group_name.equals(roleDetail.getGroup_name())) {
group_name = roleDetail.getGroup_name();
Submenu submenu = new Submenu();
submenu.setLabel(group_name);
Iterator itrInterlist = lstRoleDetail.iterator();
while (itrInterlist.hasNext()) {
roleDetailInter = (RoleDetail) itrInterlist.next();
if (group_name.equals(roleDetailInter.getGroup_name())) {
if(!roleDetailInter.getRole_function_JSF().equals("1")) {
MenuItem item = new MenuItem();
item.setValue(roleDetailInter.getRole_name());
item.setUrl(roleDetailInter.getRole_function_JSF());
submenu.getChildren().add(item);
}
else if(roleDetailInter.getRole_function_JSF().equals("1")) {
MenuItem item = new MenuItem();
Submenu submenu1 = new Submenu();
submenu1.setLabel(roleDetailInter.getRole_name());
item = new MenuItem();
item.setValue("CPU");
item.setUrl("checkList.xhtml");
submenu1.getChildren().add(item);
item = new MenuItem();
item.setValue("Monitor");
item.setUrl("monitorCheckList.xhtml");
submenu1.getChildren().add(item);
item = new MenuItem();
item.setValue("Printer");
item.setUrl("printerCheckList.xhtml");
submenu1.getChildren().add(item);
submenu.getChildren().add(submenu1);
}
}
}
model.addSubmenu(submenu);
}
}
}
请给我一个解决方案。
答案 0 :(得分:0)
此“错误”表示您尝试使用的组件在您使用的PrimeFaces版本中不存在。使用较新的版本。