• 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

Get data from managed bean method after servlet filter

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a situation to load data while JSF page loads. Also have a filter which populates user information from http request.

I was expecting the filter first to populate the user information and in the managed bean get method to verify the user information and get the data (from database). But in this case i see the managed bean get method is invoked before filter populates user information and i get null pointer exception because the user information is null.

I had to work around to get the user information from FacesContext in the managed bean get method because the user information wasn't available. Is there a way to make sure the filter is invoked first?
 
Saloon Keeper
Posts: 27764
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't really understand what that means.

A Servlet filter intercepts URL requests coming in and responses going back. It sort of sounds like you are expecting the filter to jam in extra data on incoming command requests. That's risky at best.

JSF was actually designed to be HTTP-independent. The JSF lifecycle operates in an abstract Model/View/Controller mode, which is why it's so much trouble to even get at the HttpServlet objects themselves. And it's based on Inversion of Control, which means that the JSF code isn't supposed to "go out and get" values, it expects that the values will automatically have been injected in before the action method is executed.

When I need to make an action based on a user's identity, I usually have a session-scope Managed Bean that I can inject (as a Managed Property) into the backing bean that does the business logic. That's pretty much just playing with POJOs and letting JSF do a lot of the work for me. I don't need filters or other HTTP-specific stuff to do that. In fact, I don't even need to reference the FacesContext.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic