Jun 12th, 2006, 04:54 AM
<jsp:usebean> and applicationContext problem
We are porting our struts based system to spring. At the JSP level we used some application scope beans made available using the <jsp:useBean> tag previously. These beans use the unserlying services ( constants information)
which are wired using appilcationContext XML's .
Now the problem is when i bring the system up and hit the JSP I get a NullpointerException as the bean is unable to find the wired service instances.
Is'nt the application context of spring and the container same ??
Any suggestions on how to solve this problem
Thanks in advance.
Jun 13th, 2006, 10:37 AM
I'd recommend accessing this type of constants information from a resource bundle, and not a constants type class wired as a Spring bean. Normally, this type of conversion would not be an overly time-consuming endeavor. Accessing the application context from the view layer in the way you are attempting to do so is not normally recommended. Nevertheless, a way to access Spring's ApplicationContext from a jsp would be:
<% ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContex t(request.getSession().getServletContext()); %>
Spring's ApplicationContext is not tied to the java servlet technology mechanisms, helping to explain why your attempts to directly access your 'wired' beans is failing. You could also use Spring's RequestContext from the jsp to access Spring's ApplicationContext.
Jun 14th, 2006, 01:07 AM
solved the problem..
Made a PreAction which loads the wired instances of the beans in the application context.