2011-06-17 54 views
1

你能告訴我如何添加F:setPropertyActionListener使用Primefaces在JSFF:setPropertyActionListener爲P中的項目:菜單(Primefaces)

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

     //First submenu 
     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); 
    } 

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

回答

0

要做到這一點編程菜單在編程上它是如此簡單:

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

我誤解了你的問題嗎?

+0

我想添加類似的但在編程 – aNi 2011-06-17 11:52:10

+0

或類似的東西更新的值被點擊它時 – aNi 2011-06-17 11:53:34

0
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);