aspose file tools*
The moose likes JSF and the fly likes JSF Mental Block Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "JSF Mental Block" Watch "JSF Mental Block" New topic
Author

JSF Mental Block

Jeff Calusinski
Greenhorn

Joined: Apr 21, 2005
Posts: 6
I have been using JSF for about 2 months now and I am still struggling.

I know that the JSF page is coupled to the backing bean which is bound to some managed bean. The managed bean can be in any of the three scopes (request, session, application). When I invoke a faces page, the page may have existing data based on the managed beans state. (ie. if session then the values will show on the page). Here are my problems:

1. If I want my manged bean to be in request scope (I am trying not to use session scope unless absolutely necessary) and populate the screen with data on the first invocation, how can I achive this? Using just servlets and JSP's, parameters are passed in the url and then the servlet would take the parameter out of the request object.

2. Simmilar to number 1, I constantly find I am passing parameters to do my work going from page to page. For example. A user wants to add information to the site, but must have a current subscription. If the user is not current a new page is displayed to update their subscription and then allowed to proceed with their original task.

3. How do I get data to my action that is not part of a managed bean with out using session. For example, a message id that is needed to process the action, but isn't part of the jsp page that posted the request. Are url parameters the only way to go? Or do I need to define an attribute on my view bean that contains the data. But how do I set it. This is almost a combination of #1 and #2.

It just seems to me that JSF is more OO based, but I am constantly thinking in terms of proceedural/transcationally.

Thanks in Advance.

Cheers
-Jeff

[ October 16, 2006: Message edited by: Jeff Calusinski ]
[ October 16, 2006: Message edited by: Jeff Calusinski ]
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16303
    
  21

Usually the backing bean is a managed bean!

A managed bean is managed by defining it in the facelet config xml file. Typically you'll define the bean's name, what class it is constructed from and its scope. You may also inject properties into it - which may include other managed beans. For example, I define a backing bean for a search form page as a managed bean and link it to the backing bean that does the search - which is also a managed bean.

JSF managed beans are a lot like Spring Beans, and the two can be combined in very useful ways, but that's another story.

I admit that JSF has made me use more session-scope beans than I'd like. If you're not careful with scope, either the bean will evaporate before you need it, or a new, uninitialized bean will get created and passed to you instead of the one with the data in it. Careful planning is required.

Either that, or just do the whole thing with session beans just to get the app running and then go in and reduce scope where possible. Guess which approach I use?


Customer surveys are for companies who didn't pay proper attention to begin with.
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Basically:
Backing bean: the class.
Managed bean: the instance.
So it's something like: BackingBean managedBean = new BackingBean(); Not exactly this, but you got the point?

1. If I want my manged bean to be in request scope (I am trying not to use session scope unless absolutely necessary) and populate the screen with data on the first invocation, how can I achive this? Using just servlets and JSP's, parameters are passed in the url and then the servlet would take the parameter out of the request object.
Usually I use componentbindings or valuebindings for it. Example:

JSF

MyBean

2. Simmilar to number 1, I constantly find I am passing parameters to do my work going from page to page. For example. A user wants to add information to the site, but must have a current subscription. If the user is not current a new page is displayed to update their subscription and then allowed to proceed with their original task.
Use f:attribute and/or h:inputHidden. Or use ctx.ext.getSessionMap().
3. How do I get data to my action that is not part of a managed bean with out using session. For example, a message id that is needed to process the action, but isn't part of the jsp page that posted the request. Are url parameters the only way to go? Or do I need to define an attribute on my view bean that contains the data. But how do I set it. This is almost a combination of #1 and #2.
Use f:attribute.
[ October 17, 2006: Message edited by: Bauke Scholtz ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSF Mental Block