简体   繁体   English

如何获得标签的价值 <p:menu> 素面

[英]How get value of tag <p:menu> in primefaces

I am doing a web aplication where I have a menu with a list entities and this entities will be evaluated all it is in a facelets template and I now I need to get the ID of this entity to can evaluate How it do ? 我正在做一个网络应用程序,其中有一个带有列表实体的菜单,该实体将在facelets模板中进行评估,而现在我需要获取该实体的ID才能评估其工作方式?

I thought it: 我以为:

<p:menu model="#{entidadView.menuModel}" toggleable="true"   >

     <p:ajax listener="#{grupoView.storeEntidad}"/>

</p:menu>

and My bean it is: 而我的豆子是:

public MenuModel getMenuModel(){
DefaultSubMenu subMenu2 = new DefaultSubMenu("Auditoria");
    for (Entidad entidad : getAllEntidad() ){
        item = new DefaultMenuItem(entidad.getNombre());
        item.setOutcome("/auditar.xhtml");    
        subMenu2.addElement(item);
    }

    model.addElement(subMenu2);

 //Event to Ajax
public void  storeEntidad(ValueChangeEvent evento){

    this.idEntidad = evento.getNewValue().toString();;
    System.out.println(idEntidad);

 }

but say me this error: 但是说我这个错误:

 <p:ajax> Unable to attach behavior to non-ClientBehaviorHolder parent

I did it only send the parameter by the URL of my web pages and I capture it then. 我这样做只是通过网页的URL发送参数,然后捕获了它。 My bean: 我的豆子:

public MenuModel getMenuModel(){
   DefaultSubMenu subMenu2 = new DefaultSubMenu("Auditoria");
    for (Entidad entidad : getAllEntidad() ){
       idEntidad = String.valueOf(entidad.getEntidad_id());
        item = new DefaultMenuItem(entidad.getNombre());
        item.setParam("entidad", idEntidad);
        item.setOutcome("/auditar.xhtml");    
       subMenu2.addElement(item);
}

model.addElement(subMenu2);
}

And the next Pages I capture so: 我捕获的下一页是:

<html ...>
  <f:metadata>
   <f:viewParam name="entidad" value="#{grupoView.idEntidad}"/>
  </f:metadata>

<body>

And finaally It was okay !!! 最后,还可以! (Y) (是)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM