Dynamic Menu navigate to URL with parameter

UI Components for JSF
Post Reply
kovercash
Posts: 9
Joined: 20 Oct 2010, 19:24

19 Feb 2011, 22:25

Greetings,

I am building a dynamic menu for a menubar using the menu model and would like each menuItem to navigate to a URL and pass a parameter. The menuModel is constructed in an application-scoped backing bean, whose purpose is to construct the menu model and direct selections to the appropriate page.

Code: Select all

@ManagedBean
@ApplicationScoped
public class MenuBacking {

    private MenuModel menuModel;

    @EJB
    ProductCategoryFacade categoryFacade;

     public MenuBacking() {
        menuModel = null;
    }

    public MenuModel getMenuModel() {
        return menuModel;
    }

   @PostConstruct
    public void BuildMenu() {

        Submenu submenu = null;
        MenuItem menuItem = null;
        List<ProductCategory> categoryList;

        menuModel = new DefaultMenuModel();
        submenu = new Submenu();
        submenu.setLabel("Category");

        categoryList = categoryFacade.findAll();
        for (ProductCategory category : categoryList) {
            menuItem = new MenuItem();
            menuItem.setValue(category.getCategoryName());
            menuItem.setUrl("category");
            submenu.getChildren().add(menuItem);            
        }
}
When an item is selected from the category submenu, the user is navigated to the category page but I want to be able to pass along the category ID as a parameter.

I attempted to use the Flash to store the category ID but came up against the unpleasant "JSF1095: The response was already committed by the time we tried to set the outgoing cookie for the flash." problem.

Any recomendations?

Kevin

PrimeFaces 2.2
Mojarrra 2.0.2 FCS b10
GlassFish 3.0.1

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

19 Feb 2011, 22:39

Code: Select all

menuItem.setUrl("category");
Menus dont support JSF navigation outcomes yet, so url needs to be an actual url with mapping and stuff.

kovercash
Posts: 9
Joined: 20 Oct 2010, 19:24

19 Feb 2011, 23:21

Thanks for the quick response Cagatay.

ko

tohtis
Posts: 1
Joined: 06 Oct 2011, 03:53

06 Oct 2011, 03:59

and programmatically using setActionExpression? it is possible to pass parameters to the bean that will be called?

kukeltje
Expert Member
Posts: 9605
Joined: 17 Jun 2010, 13:34
Location: Netherlands

06 Oct 2011, 08:16

Try it...

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 35 guests