views:

19

answers:

1

Hi, I got the following error:

> org.apache.jasper.JasperException: An
> exception occurred processing JSP page
> /ajax/busstop_ajax.jsp at line 12
    10: <%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%&gt;
    11: <%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%&gt;
    12: <f:loadBundle basename="/../messages.Messages" var="msg" />
    13: 
    14: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    15:    "http://www.w3.org/TR/html4/loose.dtd"&gt;


    Stacktrace:
        org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510)
        org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:419)
        org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
        org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
        org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)

    root cause

    java.lang.NullPointerException
        com.sun.faces.taglib.jsf_core.LoadBundleTag.doStartTag(LoadBundleTag.java:148)
        org.apache.jsp.ajax.busstop_005fajax_jsp._jspx_meth_f_005floadBundle_005f0(busstop_005fajax_jsp.java:184)
        org.apache.jsp.ajax.busstop_005fajax_jsp._jspService(busstop_005fajax_jsp.java:68)
        org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
        org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
        org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
        org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
        org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)

I'm trying to add a bundle to be able to translate the interface. The whole page is in jsp rather than html.

<%@page import="java.util.List"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>

<%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%&gt;
<%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%&gt;
<f:loadBundle basename="messages.Messages" var="msg" />

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd"&gt;

<f:view>
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
            <title>JSP Page</title>
        </head>
        <body>
           ...
        </body>
    </html>
</f:view>

I tried to add it in faces-config as well but no success. What am I doing wrong here? Thanks for help!

A: 

The <f:loadBundle> will throw NPE like that when the FacesContext is not present.

In other words, you aren't invoking the request through the url-pattern of the FacesServlet as definied in web.xml. The FacesServlet is namely the one who is responsible for creating the FacesContext. If the url-pattern is for example *.jsf, you should open the page in webbrowser by pagename.jsf and thus not by pagename.jsp.

The stacktrace by the way also gives evidence that it's not been processed by JSF at all. There's no single line indicating involvement of the JSF API or impl prior to calling the f:loadBundle.


That said (and unrelated to the current problem), given the fact that you're using JSF 2.0 (at least, you tagged like that) and that Facelets is the superior successor of JSP -in case of JSF-, I strongly recommend to drop JSP altogether and use Facelets instead.

BalusC