Primary redirection and action using DefaultMenuItem

I would like to use redirection and action using DefaultMenuItem

My code

MenuModel menuModel = new DefaultMenuModel(); DefaultSubMenu menu = new DefaultSubMenu("menu"); DefaultMenuItem item = new DefaultMenuItem("new Menu"); item.setCommand("redirection"); // redirection is configured in faces-config.xml item.setCommand("#{myBean.init}"); menu.addElement(item) menuModel.addElement(menu); 

but it does not work

(he worked earlier when there wasn’t

  item.setCommand("#{myBean.init}"); 

)

Apparently having two setCommand gives some problems

but i need to initialize when i click the button.

could you help me?

+1
source share
1 answer
  item.setCommand("#{myBean.init}"); 

In your bean control myBean you can have an init method like

 public String init(){ //do your business logic. return "idToBeNavigatedTo"; } 

Above will handle your business logic and redirect to the url that displays for the action id that you return to faces-config.xml

+2
source

All Articles