我试图实现一个程序化菜单栏,其中项目元素对方法的调用会抛出一个 actionListener。这不适用于 myfaces 2.1.6,但适用于 mojarra 2.1.8。我的代码有错误吗?myfaces有错误吗?
这是我的代码:
xhtml
<h:form>
<p:tabView id="head" dynamic="true" cache="true" style="width:972px;">
<p:tab id="tab1" title="Config">
</p:tab>
<p:tab id="tab2" title="Result">
<p:menubar model="#{someBean.menu}" autoDisplay="false" />
</p:tab>
</p:tabView>
</h:form>
豆java
public MenuBean() {
FacesContext facesCtx = FacesContext.getCurrentInstance();
ELContext elCtx = facesCtx.getELContext();
ExpressionFactory expFact = facesCtx.getApplication().getExpressionFactory();
menu = new DefaultMenuModel();
Submenu submenu = new Submenu();
submenu.setLabel("Dynamic Submenu 1");
MenuItem item = new MenuItem();
item.setValue("Dynamic Menuitem 1.1");
item.setId("item1");
item.setAjax(false);
MethodExpression actionListener = expFact.createMethodExpression(elCtx, "#{someBean.hello}", null, new Class[] { ActionEvent.class });
item.addActionListener(new MethodExpressionActionListener(actionListener));
submenu.getChildren().add(item);
menu.addSubmenu(submenu);
submenu = new Submenu();
submenu.setLabel("Dynamic Submenu 2");
item = new MenuItem();
item.setValue("Dynamic Menuitem 2.1");
item.setAjax(false);
item.setId("ite3");
actionListener = expFact.createMethodExpression(elCtx, "#{someBean.hello}", null, new Class[] { ActionEvent.class });
item.addActionListener(new MethodExpressionActionListener(actionListener));
submenu.getChildren().add(item);
menu.addSubmenu(submenu);}
public void hello(ActionEvent event) { System.out.println("hola2");}
有什么建议么?或从 MyFaces 更改为 Mojarra