Results 1 to 10 of 10

Thread: Null Pointer in my View

  1. #1
    Join Date
    May 2007
    Posts
    13

    Default Null Pointer in my View

    I'm trying to write a Spring based portlet and and using a JSTLView to render some JSP based views. My view is configured as follows:

    Code:
        <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
            <property name="viewClass"><value>org.springframework.web.servlet.view.JstlView</value></property>
            <property name="prefix"><value>/WEB-INF/myUWEAdminPages/</value></property>
            <property name="suffix"><value>.jsp</value></property>
        </bean>
    As far as I can see I've got all the appropriate jar files dependencies and everything set up properly (based on other apps I've written which work) but I still get the following error:

    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)
    ...
    I'm at a complete loss to understand both the error and why I'm getting it.

    Is anyone able to point me in the right direction?

    Edit: I haven't configured a message source since I don't need or want any localisation. This hasn't been a problem before, but I mention it in case it's relevant...
    Last edited by phunni; Jun 8th, 2007 at 05:13 AM.

  2. #2
    Join Date
    Sep 2004
    Location
    Manchester, NH
    Posts
    1,236

    Default

    Seems like something's not configured right related to your web application. Do you have the ContextLoaderListener set up in your web.xml file? It seems like the only way you'd get an NPE there is if your servlet context is null.
    Peter Mularien | Blog
    Author, Spring Security 3 (Book) - Packt Publishing, Available in print and eBook form
    SCJP 5, Oracle DBA
    Any postings are my own opinion, and should not be attributed to my employer or clients.


  3. #3
    Join Date
    May 2007
    Posts
    13

    Default

    I did wonder if my ServletContext might be null. I don't have a ContextLoaderListener set up in my web.xml - I've never needed that before...

    I'll give that a go...

  4. #4
    Join Date
    May 2007
    Posts
    13

    Default

    The only place I can find a reference to a ContextLoaderListener is in the docs where it says that it's useful where you want to use something other than Spring MVC. I do want to use Spring MVC (albeit a portlet flavour) so is this what I want...?

  5. #5
    Join Date
    Sep 2004
    Location
    Manchester, NH
    Posts
    1,236

    Default

    Please paste your web.xml and we'll see what's up.
    Peter Mularien | Blog
    Author, Spring Security 3 (Book) - Packt Publishing, Available in print and eBook form
    SCJP 5, Oracle DBA
    Any postings are my own opinion, and should not be attributed to my employer or clients.


  6. #6
    Join Date
    May 2007
    Posts
    13

    Default

    Here you go:

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" 
       "http://java.sun.com/dtd/web-app_2_3.dtd">
    <web-app>
    
        <servlet>
            <servlet-name>ViewRendererServlet</servlet-name>
            <servlet-class>org.springframework.web.servlet.ViewRendererServlet</servlet-class>
        </servlet>
    
        <servlet-mapping>
            <servlet-name>ViewRendererServlet</servlet-name>
            <url-pattern>/WEB-INF/servlet/view</url-pattern>
        </servlet-mapping>
        <resource-ref>
            <res-ref-name>jdbc/myUWEDb</res-ref-name>
            <res-type>javax.sql.DataSource</res-type>
            <res-auth>Container</res-auth>
        </resource-ref>
    </web-app>
    The JNDI at the end isn't actually used by anything at the moment - but it will be before development has finished...

  7. #7
    Join Date
    Sep 2004
    Location
    Manchester, NH
    Posts
    1,236

    Default

    I admit to not being familiar with Spring/portlet setup, but think you still need some aspects of the standard Spring Web MVC setup in the web.xml file in order for things to work properly (i.e. Spring config to be read/initialized, etc). This is what the ContextLoaderListener does for you.

    Also, if you aren't using the JSTL localization features, I think you can avoid using JstlView and instead use InternalResourceView. All that JstlView gives you is exposure to the Spring localization resources via the JSTL I18N tags.
    Peter Mularien | Blog
    Author, Spring Security 3 (Book) - Packt Publishing, Available in print and eBook form
    SCJP 5, Oracle DBA
    Any postings are my own opinion, and should not be attributed to my employer or clients.


  8. #8
    Join Date
    May 2007
    Posts
    13

    Default

    So I can still use all the JSTL tags and expression language in my JSPs with a InternalResourceView?

  9. #9
    Join Date
    Sep 2004
    Location
    Manchester, NH
    Posts
    1,236

    Default

    Assuming it's supported by your container, yes. I noticed that your web.xml references the servlet 2.3 spec - you may want to update that to 2.4 so that you don't run into the myriad of JSP 2.0 / EL problems that people seem to have. Remember that JSP 2.0 isn't supported natively in JSP until servlet spec 2.4.
    Peter Mularien | Blog
    Author, Spring Security 3 (Book) - Packt Publishing, Available in print and eBook form
    SCJP 5, Oracle DBA
    Any postings are my own opinion, and should not be attributed to my employer or clients.


  10. #10
    Join Date
    Sep 2004
    Location
    Arizona, USA
    Posts
    383

    Default

    Peter is right -- you definitely need the ContextLoaderListener in order for things to work right. This is what spins up all the beans that your DispatcherPortlet will work with. It becomes the parent of the ApplicationContext for your Portlet and is what gives you access to the ServletContext.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •