0

我的代码是这样的:

<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>

菜单工作正常。为什么???

谢谢

4

1 回答 1

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>
于 2013-05-01T02:23:36.897 回答