Struts 2 dynamic menu issue

View: New views
4 Messages — Rating Filter:   Alert me  

Struts 2 dynamic menu issue

by Jayaram Gokulan :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,
I use Struts2, Spring and hibernate in my project wanted to integrate Struts menu, the dynamic roles from oracle db. I followed the link
 
 I copy pasted the code snippet into an action
 

import java.util.Map;

import javax.servlet.jsp.jstl.sql.Result;

import net.sf.navigator.menu.MenuComponent;

import net.sf.navigator.menu.MenuRepository;

public class MenuBuilderAction extends BaseAction {

/**

*

*/

private static final long serialVersionUID = 1L;

MenuRepository repository = new MenuRepository();

// Get the repository from the application scope - and copy the

// DisplayerMappings from it.

MenuRepository defaultRepository = (MenuRepository) getSession()

.getAttribute(MenuRepository.MENU_REPOSITORY_KEY);

//repository.setDisplayers(defaultRepository.getDisplayers());

Result result = (Result) getSession().getAttribute("menus");

Map[] rows = result.getRows();{

for (int i = 0; i < rows.length; i++) {

MenuComponent mc = new MenuComponent();

Map row = rows[i];

String name = (String) row.get("name");

mc.setName(name);

String parent = (String) row.get("parent_name");

System.out.println(name + ", parent is: " + parent);

if (parent != null) {

MenuComponent parentMenu = repository.getMenu(parent);

if (parentMenu == null) {

System.out.println("parentMenu '" + parent

+ "' doesn't exist!");

// create a temporary parentMenu

parentMenu = new MenuComponent();

parentMenu.setName(parent);

repository.addMenu(parentMenu);

}

mc.setParent(parentMenu);

}

String title = (String) row.get("title");

mc.setTitle(title);

String location = (String) row.get("location");

mc.setLocation(location);

repository.addMenu(mc);

}

getSession().setAttribute("repository", repository);

}

}

 
My menu-config.xml
 

<?xml version="1.0" encoding="UTF-8"?>

<MenuConfig>

<Displayers>

<Displayer name="Velocity" type="net.sf.navigator.displayer.VelocityMenuDisplayer"/>

</Displayers>

<Menus>

<Menu name="MainMenu" title="mainMenu.title" page="/mainMenu.html" roles="ROLE_ADMIN,ROLE_USER"/>

</Menu>

</Menus>

</MenuConfig>

 

ApplicationConfig.xml

<bean id="menu" class="net.sf.navigator.menu.MenuLoader">

<property name="menuConfig">

<value>/WEB-INF/menu-config.xml</value>

</property>

</bean>
 
When i run my jsp i get
 
javax.servlet.jsp.JspException: The menu repository could not be found.
 
Kindly help
thanks,
Gokul

 



------------------------------------------------------------------------------

_______________________________________________
struts-menu-user mailing list
struts-menu-user@...
https://lists.sourceforge.net/lists/listinfo/struts-menu-user

Re: Struts 2 dynamic menu issue

by mraible :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Instead of registering it in your Spring applicationContext, I'd try using the MenuContextListener in your web.xml:

    <listener>
        <listener-class>net.sf.navigator.menu.MenuContextListener</listener-class>
    </listener>

If that doesn't work, look for errors on startup - you might be missing some required JARs.

Matt

On Wed, Apr 1, 2009 at 10:39 PM, Jayaram Gokulan <karamvan@...> wrote:
Hi,
I use Struts2, Spring and hibernate in my project wanted to integrate Struts menu, the dynamic roles from oracle db. I followed the link
 
 I copy pasted the code snippet into an action
 

import

java.util.Map;

import

javax.servlet.jsp.jstl.sql.Result;

import

net.sf.navigator.menu.MenuComponent;

import

net.sf.navigator.menu.MenuRepository;

public

class MenuBuilderAction extends BaseAction {

/**

*

*/

private static final long serialVersionUID = 1L;

MenuRepository

repository = new MenuRepository();

// Get the repository from the application scope - and copy the

// DisplayerMappings from it.

MenuRepository

defaultRepository = (MenuRepository) getSession()

.getAttribute(MenuRepository.

MENU_REPOSITORY_KEY);

//repository.setDisplayers(defaultRepository.getDisplayers());

Result

result = (Result) getSession().getAttribute("menus");

Map[]

rows = result.getRows();{

for (int i = 0; i < rows.length; i++) {

MenuComponent mc =

new MenuComponent();

Map row =

rows[i];

String name = (String) row.get(

"name");

mc.setName(name);

String parent = (String) row.get(

"parent_name");

System.

out.println(name + ", parent is: " + parent);

if (parent != null) {

MenuComponent parentMenu =

repository.getMenu(parent);

if (parentMenu == null) {

System.

out.println("parentMenu '" + parent

+

"' doesn't exist!");

// create a temporary parentMenu

parentMenu =

new MenuComponent();

parentMenu.setName(parent);

repository.addMenu(parentMenu);

}

mc.setParent(parentMenu);

}

String title = (String) row.get(

"title");

mc.setTitle(title);

String location = (String) row.get(

"location");

mc.setLocation(location);

repository.addMenu(mc);

}

getSession().setAttribute(

"repository", repository);

}

}

 
My menu-config.xml
 

<?

xml version="1.0" encoding="UTF-8"?>

<

MenuConfig>

<Displayers>

<Displayer name="Velocity" type="net.sf.navigator.displayer.VelocityMenuDisplayer"/>

</Displayers>

<Menus>

<Menu name="MainMenu" title="mainMenu.title" page="/mainMenu.html" roles="ROLE_ADMIN,ROLE_USER"/>

</Menu>

</Menus>

</

MenuConfig>

 

ApplicationConfig.xml

<

bean id="menu" class="net.sf.navigator.menu.MenuLoader">

<property name="menuConfig">

<value>/WEB-INF/menu-config.xml</value>

</property>
</
bean>
 
When i run my jsp i get
 
javax.servlet.jsp.JspException: The menu repository could not be found.
 
Kindly help
thanks,
Gokul

 



------------------------------------------------------------------------------

_______________________________________________
struts-menu-user mailing list
struts-menu-user@...
https://lists.sourceforge.net/lists/listinfo/struts-menu-user



------------------------------------------------------------------------------

_______________________________________________
struts-menu-user mailing list
struts-menu-user@...
https://lists.sourceforge.net/lists/listinfo/struts-menu-user

Parent Message unknown Re: Struts 2 dynamic menu issue

by Jayaram Gokulan :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks a ton for your reply Matt. I do not get the error now, but it is redirecting to some other page, while i work on that.
 
Can you please guide me on how i can fetch my menu items from database instead of menu-config.xml
 
thanks,
Gokul

--- On Wed, 4/1/09, Matt Raible <matt@...> wrote:

From: Matt Raible <matt@...>
Subject: Re: [struts-menu] Struts 2 dynamic menu issue
To: "General mailing list for Struts Menu" <struts-menu-user@...>
Date: Wednesday, April 1, 2009, 11:47 PM

Instead of registering it in your Spring applicationContext, I'd try using the MenuContextListener in your web.xml:

    <listener>
        <listener-class>net.sf.navigator.menu.MenuContextListener</listener-class>
    </listener>

If that doesn't work, look for errors on startup - you might be missing some required JARs.

Matt

On Wed, Apr 1, 2009 at 10:39 PM, Jayaram Gokulan <karamvan@...> wrote:
Hi,
I use Struts2, Spring and hibernate in my project wanted to integrate Struts menu, the dynamic roles from oracle db. I followed the link
 
 I copy pasted the code snippet into an action
 

importjava.util.Map;

importjavax.servlet.jsp.jstl.sql.Result;

importnet.sf.navigator.menu.MenuComponent;

importnet.sf.navigator.menu.MenuRepository;

publicclass MenuBuilderAction extends BaseAction {

/**

*

*/

private static final long serialVersionUID = 1L;

MenuRepository

repository = new MenuRepository();

// Get the repository from the application scope - and copy the

// DisplayerMappings from it.

MenuRepository defaultRepository = (MenuRepository) getSession()

.getAttribute(MenuRepository.MENU_REPOSITORY_KEY);

//repository.setDisplayers(defaultRepository.getDisplayers());

Result

result = (Result) getSession().getAttribute("menus");

Map[]

rows = result.getRows();{

for (int i = 0; i < rows.length; i++) {

MenuComponent mc = new MenuComponent();

Map row = rows[i];

String name = (String) row.get("name");

mc.setName(name);

String parent = (String) row.get(

"parent_name");

System.out.println(name + ", parent is: " + parent);

if (parent != null) {

MenuComponent parentMenu = repository.getMenu(parent);

if (parentMenu == null) {

System.out.println("parentMenu '" + parent

+ "' doesn't exist!");

// create a temporary parentMenu

parentMenu = new MenuComponent();

parentMenu.setName(parent);

repository.addMenu(parentMenu);

}

mc.setParent(parentMenu);

}

String title = (String) row.get(

"title");

mc.setTitle(title);

String location = (String) row.get(

"location");

mc.setLocation(location);

repository.addMenu(mc);

}

getSession().setAttribute(

"repository", repository);

}

}

 
My menu-config.xml
 

<?xml version="1.0" encoding="UTF-8"?>

<MenuConfig>

<Displayers>

<Displayer name="Velocity" type="net.sf.navigator.displayer.VelocityMenuDisplayer"/>

</Displayers>

<Menus>

<Menu name="MainMenu" title="mainMenu.title" page="/mainMenu.html" roles="ROLE_ADMIN,ROLE_USER"/>

</Menu>

</Menus>

</MenuConfig>

 

ApplicationConfig.xml

<bean id="menu" class="net.sf.navigator.menu.MenuLoader">

<property name="menuConfig">

<value>/WEB-INF/menu-config.xml</value>

</property>

</
bean>
 
When i run my jsp i get
 
javax.servlet.jsp.JspException: The menu repository could not be found.
 
Kindly help
thanks,
Gokul

 



------------------------------------------------------------------------------

_______________________________________________
struts-menu-user mailing list
struts-menu-user@...
https://lists.sourceforge.net/lists/listinfo/struts-menu-user



-----Inline Attachment Follows-----

------------------------------------------------------------------------------

-----Inline Attachment Follows-----

_______________________________________________
struts-menu-user mailing list
struts-menu-user@...
https://lists.sourceforge.net/lists/listinfo/struts-menu-user


------------------------------------------------------------------------------

_______________________________________________
struts-menu-user mailing list
struts-menu-user@...
https://lists.sourceforge.net/lists/listinfo/struts-menu-user

Re: Struts 2 dynamic menu issue

by mraible :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Change the following to fetch items from your database and iterate through them to build up your MenuComponent objects.

Result result = (Result) pageContext.getAttribute("menus");

Map[] rows = result.getRows();

for (int i=0; i < rows.length; i++) {


Matt


On Thu, Apr 2, 2009 at 8:00 AM, Jayaram Gokulan <karamvan@...> wrote:
Thanks a ton for your reply Matt. I do not get the error now, but it is redirecting to some other page, while i work on that.
 
Can you please guide me on how i can fetch my menu items from database instead of menu-config.xml
 
thanks,
Gokul

--- On Wed, 4/1/09, Matt Raible <matt@...> wrote:

From: Matt Raible <matt@...>
Subject: Re: [struts-menu] Struts 2 dynamic menu issue
To: "General mailing list for Struts Menu" <struts-menu-user@...>
Date: Wednesday, April 1, 2009, 11:47 PM


Instead of registering it in your Spring applicationContext, I'd try using the MenuContextListener in your web.xml:

    <listener>
        <listener-class>net.sf.navigator.menu.MenuContextListener</listener-class>
    </listener>

If that doesn't work, look for errors on startup - you might be missing some required JARs.

Matt

On Wed, Apr 1, 2009 at 10:39 PM, Jayaram Gokulan <karamvan@...> wrote:
Hi,
I use Struts2, Spring and hibernate in my project wanted to integrate Struts menu, the dynamic roles from oracle db. I followed the link
 
 I copy pasted the code snippet into an action
 

import

java.util.Map;

import

javax.servlet.jsp.jstl.sql.Result;

import

net.sf.navigator.menu.MenuComponent;

import

net.sf.navigator.menu.MenuRepository;

public

class MenuBuilderAction extends BaseAction {

/**

*

*/

private static final long serialVersionUID = 1L;

MenuRepository

repository = new MenuRepository();

// Get the repository from the application scope - and copy the

// DisplayerMappings from it.

MenuRepository

defaultRepository = (MenuRepository) getSession()

.getAttribute(MenuRepository.

MENU_REPOSITORY_KEY);

//repository.setDisplayers(defaultRepository.getDisplayers());

Result

result = (Result) getSession().getAttribute("menus");

Map[]

rows = result.getRows();{

for (int i = 0; i < rows.length; i++) {

MenuComponent mc =

new MenuComponent();

Map row =

rows[i];

String name = (String) row.get(

"name");

mc.setName(name);

String parent = (String) row.get(

"parent_name");

System.

out.println(name + ", parent is: " + parent);

if (parent != null) {

MenuComponent parentMenu =

repository.getMenu(parent);

if (parentMenu == null) {

System.

out.println("parentMenu '" + parent

+

"' doesn't exist!");

// create a temporary parentMenu

parentMenu =

new MenuComponent();

parentMenu.setName(parent);

repository.addMenu(parentMenu);

}

mc.setParent(parentMenu);

}

String title = (String) row.get(

"title");

mc.setTitle(title);

String location = (String) row.get(

"location");

mc.setLocation(location);

repository.addMenu(mc);

}

getSession().setAttribute(

"repository", repository);

}

}

 
My menu-config.xml
 

<?

xml version="1.0" encoding="UTF-8"?>

<

MenuConfig>

<Displayers>

<Displayer name="Velocity" type="net.sf.navigator.displayer.VelocityMenuDisplayer"/>

</Displayers>

<Menus>

<Menu name="MainMenu" title="mainMenu.title" page="/mainMenu.html" roles="ROLE_ADMIN,ROLE_USER"/>

</Menu>

</Menus>

</

MenuConfig>

 

ApplicationConfig.xml

<

bean id="menu" class="net.sf.navigator.menu.MenuLoader">

<property name="menuConfig">

<value>/WEB-INF/menu-config.xml</value>

</property>
</
bean>
 
When i run my jsp i get
 
javax.servlet.jsp.JspException: The menu repository could not be found.
 
Kindly help
thanks,
Gokul

 



------------------------------------------------------------------------------

_______________________________________________
struts-menu-user mailing list
struts-menu-user@...
https://lists.sourceforge.net/lists/listinfo/struts-menu-user



-----Inline Attachment Follows-----

------------------------------------------------------------------------------

-----Inline Attachment Follows-----


_______________________________________________
struts-menu-user mailing list
struts-menu-user@...
https://lists.sourceforge.net/lists/listinfo/struts-menu-user


------------------------------------------------------------------------------

_______________________________________________
struts-menu-user mailing list
struts-menu-user@...
https://lists.sourceforge.net/lists/listinfo/struts-menu-user



------------------------------------------------------------------------------

_______________________________________________
struts-menu-user mailing list
struts-menu-user@...
https://lists.sourceforge.net/lists/listinfo/struts-menu-user