aspose file tools*
The moose likes JSF and the fly likes How to generate managed bean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "How to generate managed bean" Watch "How to generate managed bean" New topic
Author

How to generate managed bean

Akaine Harga
Ranch Hand

Joined: Nov 03, 2009
Posts: 80

Hello

Is it possible to dynamically generate managed bean instance so it would be visible inside template?

To clarify the question:
I have several dependency fields in a multiple forms defined on the same page which uses the same set of properties. Each time I add a new registry the set is filled with different data. So when I try to submit the whole thing the first values cant apply the correspondent converter because the original values are lost to the updated ones, so the app throws an exception. In theory I could declare the same bean several times setting different alias each time but this approach limits me to some fixed quantity of bean instances and makes the whole thing look pretty ugly.

A simplified example:
1. I have a catalogue with 3 properties: states, municipalities and districts defined in a managed bean as List<SelectItem> to simplify the injection into the rich:comboBox elements. Each time I select a state the municipality property is getting filled with correspondent data and related comboBox is updated. Same happens for district when I chose a municipality. To solve the context persistence problem I use rich:keepAlive tag.

2. Later in the form I have an additional info in its independent form which has a similar set of fields (just different target values and ids) that use the same approach using the same managed bean. And of course after I fill the last ones catalog.municipalities and catalog.districts are left with data different from the first set. So when I try to submit I get an error since the converter can't return text to ids from the first fieldset:


I am looking for a way to avoid usage of multiple declarations of the same managed bean in my faces config.


Wanna install linux on a vacuum cleaner. Could anyone tell me which distro sucks better?
willCodeForFood("Java,PHP,C#,XML,VBS,XHTML,CSS,JavaScript,SQL"); //always looking for job opportunities in AU/NZ/US/CA/Europe :P
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16141
    
  21

Please spare us the red text!

Managed Beans are simply standard JavaBeans whose construction and cross-linkage are statically defined in the faces-config file(s). The only difference between (for example) a managed session-scope bean and a non-managed session-scope bean is that the non-managed bean has to be created, initialized and added to the session by you.

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

Joined: Nov 03, 2009
Posts: 80

Thanks for the answer and sorry for the red text. Didn't know this: I'm aware each community has its unofficial rules. I spent several years of my life fighting for clean messages on codeguru forums myself and I'm new to coderanch. Will behave myself, promise...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to generate managed bean