• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

What is the function of the listener com.sun.faces.config.configureListener?

 
Ranch Hand
Posts: 893
Tomcat Server Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I had a problem where sometimes the FacesContext.getCurrentInstance() returns null.

In a thread I've read that adding the listener com.sun.faces.config.configureListener could solve this issue.

I tried to found the exact function of this listener but could not find a good answer.

Maybe someone could give me some information or a hint where to find.

Thanks in advance.
 
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When exactly did it return null? You need to realize that the FacesContext is only available if the FacesServlet is invoked by a matching URL.
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Remko,

I am assuming you are trying to access FacesContext in ServletFilter. This is where you would FacesContext as null since CurrentFacesContext is set in FacesServlet and Pre Filters are invoked before FacesServlet.
There are known ways of solving this. Best way is discussed here:
http://www.thoughtsabout.net/blog/archives/000033.html

Also you might want to check if you want to use ServletFilter or PhaseListener for your problem.

Kumar.
javaswany.blogspot.com


Remko Strating wrote:I had a problem where sometimes the FacesContext.getCurrentInstance() returns null.

In a thread I've read that adding the listener com.sun.faces.config.configureListener could solve this issue.

I tried to found the exact function of this listener but could not find a good answer.

Maybe someone could give me some information or a hint where to find.

Thanks in advance.

 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't recommend this approach.

If he is indeed trying to get the FacesContext inside a Filter, then there's a flaw in his design and he need to elaborate why he needs the FacesContext. If it is just for accessing managed beans or some other scoped attributes or some other stuff made available by request, session and application, he could perfectly use the (Http)ServletRequest for this which is already available inside a Filter.

By the way, why are you spamming an irrelevant link to your blog in every post? If you like to share it with others and want to increase your traffic, just place it in your signature.
 
Kumar Mettu
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bauke,

Please see last line of my message about PhaseListner and Servlet Filter.
Also I am not trying to spam. I am returning to JavaRanch after 1999-2000 again and still haven't gotten used to JavaRanch.
Thanks for the Tip.

Kumar.

Bauke Scholtz wrote:I don't recommend this approach.

If he is indeed trying to get the FacesContext inside a Filter, then there's a flaw in his design and he need to elaborate why he needs the FacesContext. If it is just for accessing managed beans or some other scoped attributes or some other stuff made available by request, session and application, he could perfectly use the (Http)ServletRequest for this which is already available inside a Filter.

By the way, why are you spamming an irrelevant link to your blog in every post? If you like to share it with others and want to increase your traffic, just place it in your signature.

 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A PhaseListener is only useful if he want to access the JSF components or want to hook on specific JSF phases. Things which I don't see to happen in a Filter which he initially wanted to use.

Well, instead of keep guessing we can also just wait for his reply on my question why actually he needs the FacesContext instance.
 
Remko Strating
Ranch Hand
Posts: 893
Tomcat Server Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your support

I use the facescontext for finding a relation between two managed beans. In one I store some user information which is used in a second one by the initialisation in which the name of the creator is gathered from the other managed bean. Mostly this works well, but sometimes the facescontext is null. For which I check and fills in the default user.

From your reaction I will check if the FacesServlet is invoked by a matching URL.

 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Remko Strating wrote:I use the facescontext for finding a relation between two managed beans.

Request scoped beans are just accessible by HttpServletRequest#getAttribute(), session scoped beans by HttpSession#getAttribute() and application scoped beans by ServletContext#getAttribute(). In the other way you can just set them by setAttribute().

With this information you must be able to solve this problem without the need for FacesContext.

Apart from that and continuing with the "flaw-in-design" story, are you familiar with managed properties? Are you aware that you can perfectly inject beans in each other as managed property using faces-config.xml? It really sounds like that you want to associate beans with each other. You don´t need a Filter for this.
 
Remko Strating
Ranch Hand
Posts: 893
Tomcat Server Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks voor your feedback I will try the HttpSession, because both beans are session scoped.

I was aware of managed properties, but not aware that I could inject complete beans with each other.

In the examples of managed properties I have seen only simple types are used. I will try it with complete beans.



 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It´s fairly simple. You can find here an example: http://balusc.blogspot.com/2006/06/communication-in-jsf.html#InjectingManagedBeansInEachOther
 
Remko Strating
Ranch Hand
Posts: 893
Tomcat Server Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks I have solved it with a managed property it was fairly simple.

I will test it and if it works good, I will replace my current code with this solution because it's much cleaner than managing the relationships within the code.

Your other remark by solving it with the help of the HttpSession I could not understand.

I need to use the FacesContext.getCurrentInstance() for getting an ExternalContext which I could use for getting the SessionScoped beans or is there a different way for getting the ExternalContext. The reason for this is if the FacesContext.getCurrentInstance returns null. I will have a null pointer exception when getting the ExternalContext.
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JSF API runs on top of Servlet API. JSF stores session scoped beans in the session scope. In Servlet terms that´s just to be done by getting/setting it as attribute of the HttpSession.

ExternalContext#getSessionMap() returns basically a modifable map of HttpSession attributes. Under the hood it just does HttpSession#get/setAttribute(). Exactly the thing which you can also do in a Filter.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic