Struts2 jQuery UI dynamic Menu from Action List

Tags: , , , ,

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(){
    return "success";
public List<String> getMenuList() {
    return menuList;
public void setMenuList(List<String> menuList) {
    this.menuList = menuList;


<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){ = id;
        this.menuItems = menuItems;

    public String getId() {
        return id;
    public void setId(String 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; = 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) { = menu;

How to configure this in JSP page with sj:menu tag?


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.

Source: stackoverflow