wood burning stoves 2.0*
The moose likes JSF and the fly likes Value bean or backing bean? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Value bean or backing bean?" Watch "Value bean or backing bean?" New topic
Author

Value bean or backing bean?

Kev D'Arcy
Ranch Hand

Joined: Jul 26, 2001
Posts: 75
Hi all,

Just a general query... Is it better/easier to use a backing bean (a bean that contains input objects that are "bound" to the front end screens) or a value bean (a bean that contains the "values" entered/to be displayed on the front end) to managed the front end of an application. I've tried both of them and they both seem to have pros and cons. All opinions welcome!

Cheers,

Kev
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

I do a slight combination of both. For very simple pages I use the managed beans that are stricktly related to the page itself. For more complex pages I'll have a managed beans but I might also have a value object that I have in the session.

For example, in one of my applications I have a page where I gather information about a Help Desk Issue. I have a VO called Issue that stores all the important information. I always have an instance of a current issue in another VO called Visit which is stored in the session. On my newissue.jsp I just update the current issue directly instead of gathering up values in the managed bean and then copying them over. So I'll have something like:

<h:inputText value="#{visit.currentIssue.machineName}" .../>

I haven't ran into any snags with this approach yet.


GenRocket - Experts at Building Test Data
Kev D'Arcy
Ranch Hand

Joined: Jul 26, 2001
Posts: 75
Greg,

I have a reasonably complex page and I'm using a value bean to present data to the front end, but I'm seeing some inconsistencies... Sometimes the data is displayed correctly and sometimes it isn't. I'm wondering if I should just use a backing bean to present/receive the data and just transfer the values to/from the value bean...
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

I'd so go with what works.

That being said, how are you storing your value bean? Session, Request, etc? When and how are you updating it?
Varun Khanna
Ranch Hand

Joined: May 30, 2002
Posts: 1400
I use a combination of both and seems to wrok fine till now.
Originally posted by Kev D'Arcy:
Greg,

I have a reasonably complex page and I'm using a value bean to present data to the front end, but I'm seeing some inconsistencies... ...


What kind of inconsistencies ?


- Varun
Kev D'Arcy
Ranch Hand

Joined: Jul 26, 2001
Posts: 75
Greg,

I'm storing the value bean in a session object. It get's updated either via front end forms (through value links to inputs), or via code in the app to clear down values.

Kev
Kev D'Arcy
Ranch Hand

Joined: Jul 26, 2001
Posts: 75
Varun,

What I'm seeing is that when the value bean gets cleared down (either explicitly through the application or by going to a new page) and a user returns to the page displaying the value bean properties, some of the value beans properties don't get displayed on the JSP.

Kev
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Originally posted by Kev D'Arcy:
Varun,

What I'm seeing is that when the value bean gets cleared down (either explicitly through the application or by going to a new page) and a user returns to the page displaying the value bean properties, some of the value beans properties don't get displayed on the JSP.

Kev


What do you mean by "cleared down" and how are they returning to the previous page? I think your problem may just be a logic issue rather than a technical issue. I have no problems updating the properties in session objects from pages or code.
Kev D'Arcy
Ranch Hand

Joined: Jul 26, 2001
Posts: 75
It's probably easier if I show you the code. Can i upload it somewhere or will I just embed it into a post?
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Just post the code in here. Be sure and use UBB code tags


[/code]

And disable smilies.
Kev D'Arcy
Ranch Hand

Joined: Jul 26, 2001
Posts: 75
Greg,

This is the JSP 1.:


This is an example of one of the jspfs:


And the code in the action bean:
Kev D'Arcy
Ranch Hand

Joined: Jul 26, 2001
Posts: 75
Greg,

What happens is that when I'm clearing down the form, I use a javascript function to clear the form values and the blank fields get sent up and handled by and "immediate" action funtion. If someone leaves this page (via a hyperlink), and then returns to it with the value bean having already been populated with new values (via the getIssueData() method), the new values are not displayed on the screen (the default values form the form clear are though).
Zafar Hakim
Greenhorn

Joined: Nov 04, 2008
Posts: 6

Does any one know solution to this problem. I too am facing similar problem.

Problem:
I have a page with data table --- I open a new modal dialog window (window.showModalDialog) on click of menu item on a page --> It opens the page to view details of the item. When I close it and select different row of the table and open to see the details it shows the previous data.

The data on the form fields are populated from a backing bean which is session scoped. I am sure the backing bean is updated with new data. Only that it is not displayed/refreshed in the page rendered.

Thanks for your time.

Regards,
Hakim
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Please do not resurrect old topics nor hijack otherĀ“s topics. Start your own for each independent problem. Users here usually respond to the topicstarter only.
Zafar Hakim
Greenhorn

Joined: Nov 04, 2008
Posts: 6
Bauke,
thanks for your suggestion..
 
wood burning stoves
 
subject: Value bean or backing bean?