• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

JSF Mental Block

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Saloon Keeper
Posts: 28469
210
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
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?
 
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Get me the mayor's office! I need to tell him about this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic