它在动态菜单中不起作用'actionExpresion'。 PrimeFaces

时间:2012-05-30 12:52:51

标签: jsf-2 primefaces

我的代码就像:

<h:form>

<p:accordionPanel>
    <p:tab title="TAB 1">
    <h:panelGrid columns="2" cellpadding="10">
        <p:menu model="#{usuarioSesion.miMenu}" />
    </h:panelGrid>
    </p:tab>
    <p:tab title="TAB 2">
    <h:panelGrid columns="2" cellpadding="10">
            Ayuda
    </h:panelGrid>
    </p:tab>            
</p:accordionPanel>

</h:form>

我的托管bean就像:

@ManagedBean(name = "usuarioSesion")
@SessionScoped
public class UsuarioCtrl implements Serializable{

    private DefaultMenuModel miMenu;

    @SuppressWarnings("unused")
    @PostConstruct
    private void init(){
        FacesContext facesContext = FacesContext.getCurrentInstance();
        Application application = facesContext.getApplication();
        ExpressionFactory expressionFactory = application.getExpressionFactory();
        ELContext elContext = facesContext.getELContext();

        miMenu = new DefaultMenuModel();
        Submenu submenu;
        submenu = new Submenu();
        submenu.setId("idCabecera");
        submenu.setLabel("Operaciones");

        MenuItem item = new MenuItem();
        item.setValue("Organismos");
        item.setId("idOrganismo");
        item.setActionExpression(expressionFactory.createMethodExpression(elContext, "#{usuarioSesion.listar2}", String.class, new Class[0]));
        item.setAjax(false);
        item.setAsync(false);
        submenu.getChildren().add(item);

        MenuItem item2 = new MenuItem();
        item2.setId("idAplicacion");
        item2.setValue("Aplicacion");
        item2.setActionExpression(expressionFactory.createMethodExpression(elContext, "#{usuarioSesion.listar1}", String.class, new Class[0]));
        item2.setAjax(false);
        item2.setAsync(false);
        submenu.getChildren().add(item2);

        miMenu.addSubmenu(submenu);

    }

    public String listar1(){
        .....
    }

    public String listar2(){
        .....
    }

当我单击菜单项时运行此代码时,方法listar1(),listar2()永远不会执行。

是什么原因?

但是这段代码:

<h:form>
      <h:panelGrid columns="2" cellpadding="10">
         <p:menu model="#{usuarioSesion.miMenu}" />
   </h:panelGrid>
</h:form>

菜单运行正常。为什么???

感谢

1 个答案:

答案 0 :(得分:0)

解决方法:我发现添加:

<h:panelGrid columns="2" cellpadding="10" style="display:none">
    <p:menu model="#{usuarioSesion.miMenu}" />
</h:panelGrid>

到您的表单,解决问题。最终的表格内容是:

<h:form>
<p:accordionPanel>
    <p:tab title="TAB 1">
    <h:panelGrid columns="2" cellpadding="10">
        <p:menu model="#{usuarioSesion.miMenu}" />
    </h:panelGrid>
    </p:tab>
    <p:tab title="TAB 2">
    <h:panelGrid columns="2" cellpadding="10">
            Ayuda
    </h:panelGrid>
    </p:tab>            
</p:accordionPanel>
<h:panelGrid columns="2" cellpadding="10" style="display:none">
    <p:menu model="#{usuarioSesion.miMenu}" />
</h:panelGrid>
</h:form>