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);
精彩评论