• Post Reply Bookmark Topic Watch Topic
  • New Topic

Newer to JSF, looking for some clearification

 
Chris Boldon
Ranch Hand
Posts: 190
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I'm new to JSF, I'm an old Struts guy.
I've been in the books and google for awhile now. I have a few things I'd like clearification on.

Managed Beans: It appears that the managed bean takes the place of both the Struts action and Struts form at the same time. The managed bean is where the values from a form are mapped to, and where the Java logic methods are executed. Correct?

If I am correct about this, how do you go about passing a value object(transfer object) to another layer? Do you have to instantiate a new value object, map the values, and pass that? I'm doubting that is what happens since it would be redundant coding.

Hopefully I was clear enough. Thank you in advance.
 
Tim Holloway
Bartender
Posts: 18470
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
While I always feel obliged to point out that true MVC is impossible for any HTTP system, JSF is about is close as you can get. The backing bean - technically not all managed beans are backing beans - is a model in MVS terms, and therefore isn't a good fit to be pulled directly from the data model. Then again, in Struts, the Form Bean COULD not be pulled directly from the data model, since it had to subclass the Struts ActionForm.

A reasonable compromise (and one I often use) is to place the DTO as a component of the backing bean. Or, where possible, skip the DTO entirely and use the model object.

Thus, if you have a datamodel object of type AccountInfo, you'd define a getter for it in the backing bean (let's say it's a MyBean named "myBean") and let magic of EL do the rest:

<:inputText id="userName" value="#{myBean.accountInfo.userName}/>

Since the formatters and validators are all applied externally, this all works quite well for most cases.

Some cases aren't so well handled by connecting the view so directly to the datamodel. For example, the setter might have side-effects, although that's usually bad practice. Or an conversion beyond the scope of the standard formatters might be needed. In that case, you'd define the property either directly on the backing bean for simplicity or via a facade.
 
Chris Boldon
Ranch Hand
Posts: 190
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim,

Thank you very much! You have been a big help. I couldn't find a 'tutorial' or 'sample' anywhere that layed out what you just explained. Something about their method just have a bad code feel (well...tutorials aren't designed for production implementation I suppose).

I'm ready to hit the JSF hard and never look back at Struts.
 
Gravity is a harsh mistress. But this tiny ad is pretty easy to deal with:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!