How can I generate dynamic menu & menu items from a list generated at Action? I tried this approach but it is generating only main menu but not sub-menus.
Action class:
private List<String> menuList = new ArrayList<String>(); public String execute(){ menuList.add("Menu1"); menuList.add("Menu2"); menuList.add("Menu3"); menuList.add("Menu4"); return "success"; } public List<String> getMenuList() { return menuList; } public void setMenuList(List<String> menuList) { this.menuList = menuList; }
JSP:
<sj:menu cssStyle="width:50%" list="menuList" />
What can i do to get Menu with menu items?
Example classes structure:
public class Menu { private String id; private List<MenuItem> menuItems; public Menu(String id, List<MenuItem> menuItems){ this.id = id; this.menuItems = menuItems; } public String getId() { return id; } public void setId(String id) { this.id = id; } public List<MenuItem> getMenuItems() { return menuItems; } public void setMenuItems(List<MenuItem> menuItems) { this.menuItems = menuItems; } } public class MenuItem { private String title; private String href; private Menu menu; // submenu public MenuItem(String title, String href, Menu menu){ this.title = title; this.href = href; this.menu = menu; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public String getHref() { return href; } public void setHref(String href) { this.href = href; } public Menu getMenu() { return menu; } public void setMenu(Menu menu) { this.menu = menu; } }
How to configure this in JSP page with sj:menu
tag?
Advertisement
Answer
The <sj:menu>
tag generates a menu from list values, to create submenu you should use <sj:menuItem>
in the body of <sj:menu>
tag.
Also in the body of <sj:menuItem>
you can use <sj:menu>
tag.
The detailed explanation and example you can find here.