Q about managed- & backingbeans

Hi,

I am "redesigning" my managed beans and I want to split a few beans into managed beans and backing beans.

For instance, I have got a JSP file with an Inputtextfield name with value="#{abean.name)". Now, I have to store that name into a Database and want to put the action-handling (submit Button - action) into a extra backing bean.

So I have to write <h:inputtext id="name" value="#{abean.name)" binding="#backing_abean.nameInput"> to split the event-handling from the state-holding stuff, but unfortunately I have overhead because I "got" the name twice (abean.name and backing_abean.name). Is that ok or is there a better solution to split a bean into managed and backing beans?

Thnx

Alex

[740 byte] By [Troilusa] at [2007-11-27 1:06:52]
# 1
Please first explain in your own words what's the difference is between backing and managed beans. This because I've a guess that you're misunderstanding it.
BalusCa at 2007-7-11 23:42:03 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

Hi,

I think that I could putting the eventhandling, validation and convertion methods into the Backing Beans and the state-save methods/variables (to fill selectOneMenus with Data for instance) "are" in the managed beans. Backing Beans should only be in request scope. Thats all what I know about it :)

My managed bean "beanA" contains everthing in one session-bean for now. Variables for the inputFields, binding to read a row from a table, validations and Actionevents to navigate to other views or to store data into a database. I think thats not the best practice and I could split the handler, validators, etc in that way. But if I am mistaken then I am sorry and I hope you could tell me what Backing Beans are there usually for.

Thnx

Alex

Troilusa at 2007-7-11 23:42:03 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

No, it isn't. Simplified: managed beans are instances of backing beans which are made available to the JSF pages by defining them in the faces-config.xml. It is independent of the scope and the use purposes.

What you're talking about is splitting the componentbindings, valuebindings, validators and actions in multiple backingbeans and accessing them using different managed beans.

I don't think that this is a good design. It might work, but it is somewhat awkward. Rather think in OO and eventually look to the size of the application. Also review if you really need all component bindings being definied in the backing bean, usually just valuebindings are sufficient.

Rather use DTO's for the values and keep the component bindings and actions in backing beans. I'm used to use one (subclassed) backing bean per page (which can have multiple forms and/or buttons). When a webapp has more than one form and you want to share methods, then create a "superbean" with the shared methods in it and subclass backing beans from it.

BalusCa at 2007-7-11 23:42:03 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

Hi, thanks for your reply. I think I don't understand everything but the Backing-Bean definition from the sun J2EE 1.4 Glossary tells me that all my Beans are backing beans yet. Therefore I don't split my beans wrongly and let them as their are now.

Otherwise, are Managed Beans perhaps beans which I only define and fill in the faces-config.xml? (fill lists with list-entries, init values with {#params....} and so on?).

Best regards

Alex

Troilusa at 2007-7-11 23:42:03 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5
Simplified in code terms: mypackage.MyBean.class = Backing bean.{#myBean} = Managed bean.
BalusCa at 2007-7-11 23:42:03 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6
Ahhh, thnx now I have got it :)
Troilusa at 2007-7-11 23:42:03 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...