开发者

f:setPropertyActionListener for items in p:menu (Primefaces)

开发者 https://www.devze.com 2023-03-13 19:36 出处:网络
Can you show me how to add f:setPropertyActionListener for Programmatic Menu using Primefaces in jsf public MenuBean() {

Can you show me how to add f:setPropertyActionListener for Programmatic Menu using Primefaces in jsf

public MenuBean() {  
        model = new DefaultMenuModel();  

        //First submenu  
    开发者_C百科    Submenu submenu = new Submenu();  
        submenu.setLabel("Dynamic Submenu 1");  

        MenuItem item = new MenuItem();  
        item.setValue("Dynamic Menuitem 1.1");  
        item.setUrl("#");  
        submenu.getChildren().add(item);  

        model.addSubmenu(submenu);  

        //Second submenu  
        submenu = new Submenu();  
        submenu.setLabel("Dynamic Submenu 2");  

        item = new MenuItem();  
        item.setValue("Dynamic Menuitem 2.1");  
        item.setUrl("#");  
        submenu.getChildren().add(item);  

        item = new MenuItem();  
        item.setValue("Dynamic Menuitem 2.2");  
        item.setUrl("#");  
        submenu.getChildren().add(item);  

        model.addSubmenu(submenu);  
    } 

and

 <p:menu model="#{menuBean.model}"/>  


To do this programatically it is as simple as:

MenuItem item = new MenuItem();
item.addActionListener(listener);

Did I misunderstand your question?


import javax.faces.event.ActionListener;
import com.sun.faces.taglib.jsf_core.SetPropertyActionListenerImpl;
...
//setPropertyActionListener
                ValueExpression target = expFact.createValueExpression(elCtx, "#{TesterBean.someProperty}", String.class);
                ValueExpression value  = expFact.createValueExpression(strProperty, String.class);
                ActionListener handler = new SetPropertyActionListenerImpl( target , value );
                newCommandLink.addActionListener(handler);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号