tags:

views:

395

answers:

2

I am getting the below messages when my JSF page gets rendered. The page is rendered correctly however in the Console the message below repeats itself numerous times...

INFO: ERROR: Unable to get Faces Context for session variable: localeBean

11:54:27,090 INFO [STDOUT] Nov 24, 2009 11:54:27 AM com.web.util.faces.UtilFacesFuncs log INFO: Most likely, you've requested a Faces object from a NON-Faces (i.e. Servlet) context.

In my JSF I am usign localebean as follows:

<f:view locale="#{localeBean.userLocaleLoggedIn}">

In the faces-config file I have it defined as below:

<managed-bean>
 <description>Locale Bean</description>
 <managed-bean-name>localeBean</managed-bean-name>
 <managed-bean-class>com.mg.faces.LocaleBean</managed-bean-class>
 <managed-bean-scope>session</managed-bean-scope>
</managed-bean>

In my class LocaleBean there is a method getUserLocaleLoggedIn() which is the code that gets executed when the JSF page executes:

  <f:view locale="#{localeBean.userLocaleLoggedIn}">

On debugging my jsp I can see that method being called and everyhting is fine, I debug my jsp all the way thru till it creates the footer, just when it is rendering to the browser these errors are thrown about 20 + times repeatedly. It only happens on tihs jsp as it is a new one I have added. I tried comparing with existing jso I cannot see anything different, Does anyone know what I shud be looking out for?

Any help much appreciated.

Thanks.

Regards

A: 

This error basically means that the request URL (the one which you see in the browser address bar, or the one which is used to include/dispatch the desired page) does not match the url-pattern of the FacesServlet's mapping as definied in the web.xml. You need to let the request URL match it to invoke the FacesServlet.

So if it is for example the following suffix-pattern (extension mapping):

<url-pattern>*.jsf</url-pattern>

then you need to ensure that your request URL matches it, i.e. use http://example.com/context/page.jsf instead of http://example.com/context/page.jsp.

Or if it is for example the following prefix-pattern (directory mapping):

<url-pattern>/faces/*</url-pattern>

then you need to ensure that your request URL look like http://example.com/context/faces/page.jsp instead of http://example.com/context/page.jsp.

Edit: although I wouldn't use multiple url-patterns for the FacesServlet and just stick to one, but the mapping seems to look fine. After all, the error message thus comes from com.web.util.faces.UtilFacesFuncs. That look like a homegrown utility class. What exactly is that class doing? Isn't it just a bug in that utility class that it for example is trying to access the FacesContext too early or too late in the request?

BalusC
In my web.xml I have the following mappings: <servlet-mapping> <servlet-name>Faces Servlet</servlet-name> <url-pattern>/faces/*</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>Faces Servlet</servlet-name> <url-pattern>*.faces</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>Faces Servlet</servlet-name> <url-pattern>*.jsf</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>Faces Servlet</servlet-name> <url-pattern>*.htm</url-pattern> </servlet-mapping>
msharma
A: 

Sorry my comment I added above did not come across correctly, here is what I have in my web.xml: Also my url I use is http://localhost.com/context/register/mypage.htm I have these jsp under the folder register. I can call other jsp from the register folder and this error does not appear.... just happens for this particular jsp that I have added.

<servlet-mapping>
  <servlet-name>Faces Servlet</servlet-name>
  <url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
  <servlet-name>Faces Servlet</servlet-name>
  <url-pattern>*.faces</url-pattern>
</servlet-mapping>
<servlet-mapping>
  <servlet-name>Faces Servlet</servlet-name>
  <url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<servlet-mapping>
  <servlet-name>Faces Servlet</servlet-name>
  <url-pattern>*.htm</url-pattern>
</servlet-mapping>

I am trying to add my full mappings but the way the code tags work here, it is not coming across since hte mappings have tags... I tried blockquotes provided, but still this editor is not able to display my mappings correctly, apologies!

Any idea how I should be calling my url. Thanks.

msharma
The order of answers is based on votes, so please edit the question in future.
McDowell