PDA

View Full Version : using JSTL 1.0 with Portlet MVC


fberteau
Oct 11th, 2007, 09:47 AM
Hello,

I am a newwbee in developping portlet with Spring Portlet MVC.
I am developping a portlet with Eclipse 3.3 + Jetspeed 2 + Spring Portlet MVC.

When I try to deploy this first JSP with JSTL tags:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<h2>Requesters list</h2>

... Jetspeed always crash with theses errors:
14501 [http-8080-Processor25] INFO org.springframework.web.portlet.DispatcherPortlet - FrameworkPortlet 'Check-in': initialization completed in 2625 m
s
14501 [http-8080-Processor25] INFO org.springframework.web.portlet.DispatcherPortlet - Portlet 'Check-in' configured successfully
15235 [http-8080-Processor25] ERROR org.springframework.web.portlet.DispatcherPortlet - Could not complete request
java.lang.NullPointerException
at org.springframework.web.servlet.support.JstlUtils. getJstlAwareMessageSource(JstlUtils.java:57)
at org.springframework.web.servlet.view.JstlView.init ApplicationContext(JstlView.java:76)
at org.springframework.context.support.ApplicationObj ectSupport.setApplicationContext(ApplicationObject Support.java:73)

In fact whatever code I put in the JSP, as soon as I use JstlView, I have this crash message from JetSpeed.

I inform you that I want to use JSTL 1.0 because the target is WAS 5.1.

Any idea ?

Thanks

fberteau
Oct 11th, 2007, 09:51 AM
I have forgotten to provide you the concerned part of my beans file:

<bean id="messageSource"
class="org.springframework.context.support.ResourceBundle MessageSource">
<property name="basename" value="message" />
</bean>

<bean id="listRequesterController"
class="org.springframework.web.portlet.mvc.Parameterizabl eViewController">
<property name="viewName" value="requesters" />
</bean>

<bean id="portletModeParameterHandlerMapping"
class="org.springframework.web.portlet.handler.PortletMod eHandlerMapping">
<property name="portletModeMap">
<map>
<entry key="view">
<ref bean="listRequesterController" />
</entry>
</map>
</property>
</bean>

<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResou rceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
<property name="viewClass"
value="org.springframework.web.servlet.view.JstlView" />
</bean>

fberteau
Oct 12th, 2007, 04:47 AM
Please, this help is very urgent !

johnalewis
Oct 12th, 2007, 02:36 PM
This is probably happening because your portlet ApplicationContext does not have access to the ServletContext for the webapp.

Not sure if this is the cause of your crash, but the viewResolver should really be declared in the root ApplicationContext for your webapp, not in the ApplicationContext specific to the portlet.

fberteau
Oct 15th, 2007, 06:15 AM
I am not sure to understand your explanation.

My view resolver is declared in the file /WEB-INF/Check-in-portlet.xml (the project's name is Check-in), in order to respect Spring MVC rules:

...
<bean id="messageSource"
class="org.springframework.context.support.ResourceBundle MessageSource">
<property name="basename" value="message" />
</bean>

<bean id="listRequesterController"
class="org.springframework.web.portlet.mvc.Parameterizabl eViewController">
<property name="viewName" value="requesters" />
</bean>

<bean id="portletModeParameterHandlerMapping"
class="org.springframework.web.portlet.handler.PortletMod eHandlerMapping">
<property name="portletModeMap">
<map>
<entry key="view">
<ref bean="listRequesterController" />
</entry>
</map>
</property>
</bean>

<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResou rceViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>

I am not sure where to put the message.properties file, so I have try in /WEB-INF/ directory and in /WEB-INF/classes one, but there is no difference, the same exception occurs.

johnalewis
Oct 15th, 2007, 01:20 PM
Normally, you want to have (at least) two different ApplicationContext definition files.

The first is one that contains resources for the entire webapp. This file is commonly named applicationContext.xml and is loaded by a ContextLoaderListener declaration in the web.xml file. This is where you should put your ViewResolver declaration.

The second one is for the specific portlet -- if your webapp has more than one portlet, then there should be one file per portlet. This is where you put resources specific to that portlet (handler mappings, controllers, etc.)

In any case, you must have at least the two ApplicationContext definitions, otherwise your portlet webapp does not have access to the ServletContext, which is what is causing your problem.

If you look at one of the sample Spring Portlet MVC applications, either the one in Spring CVS or the the one on the wiki (http://opensource.atlassian.com/confluence/spring/display/JSR168/Home), you will see examples of this configuration.

fberteau
Oct 16th, 2007, 03:55 AM
Many thanks to you, jonhalewis, you are right !

I have created an "applicationContext.xml" file with my views resolver and everything is right now. I did not understood that by reading the Spring documentation.

Have a nice day !