This week's giveaway is in the EJB and other Java EE Technologies forum. We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line! See this thread for details.
I've been looking around for this for quite some time now but i'm not sure this is exactly the right method.
I want to pass a value to my managed bean without user interaction, i've seen how it is done with user interaction, but without is the tricky one. My scenario is, the user has logged in, they now want to see a list of details on the database based on their logged on user. The parameter that i want to pass is in session. How can i get access to this to set it without user interaction?
If your bean is Session Scoped, you may want to alter the bean value the moment the variable is created in the session. That way, the bean will already hold the value you want when you make the request.
If you're using J2EE-standard container-managed security, you can obtain the userid from the UserPrincipal object referenced by your HttpServletRequest and use that as a key to retrieve further details. If you're not, you're on your own.
HTTP is strictly a request/response protocol, so some sort of client (user) request is required to do anything. So you'd normally handle that as part of the response preparation process.
Customer surveys are for companies who didn't pay proper attention to begin with.
Joined: Apr 23, 2011
Thanks guys, i wondered why it was proving so hard to find lol.
So if i have a POJO that i use to process the request (once it has been submitted to my servlet (not faces servlet) controller & been redirected based on my action) to do CRUD etc if i'm processing a form but don't have any sort of controller for users clicking links in the site, how can i do this?
I guess there's 2 questions in there:
1. How can my POJO class that does processing, instantiate the managed bean & set the user variable & then the JSP/JSF use that same instance?
2. Should i be using a controller for every click, even hyperlinks? I guess if i do & i submit to a controller which can instantiate the managed bean then that seems sensible.
The beans in JSF are the same as they are in straight J2EE. So if you create a session-scope bean in a servlet or JSP, a later JSF request will be able to access it. The only difference is that if JSF accesses the bean first, JSF will automatically construct initialize the bean and bind it as a session attribute. Servlets and JSPs have to do the grunt work themselves.
Since JSF only works properly on requests routed through the FacesServlet, you don't need any special controller services - the FacesServlet is the only controller you'll have to worry about. You can't have a request come into a servlet and out through JSF - only JSF-routed URLs will process JSF properly. Non-JSF URLs will operate independently - allowing for shared objects like session beans and so forth.
Joined: Apr 23, 2011
Sorry for all these newbie questions but i just can't seem to find one way to structure my web app.
I guess i understand it a bit better now.
Another quick question, i've noticed the managed beans have different annotations when i've tried different examples & they don't seem to work for me cos my IDE (eclipse) doesn't know about these annotations...do i need to create these @interfaces?