Good article.  His packaging is a little different than ours.  For his
Calculator example, we would have separated the Calculator's data into
CalculatorBean, and our CalculatorAction (or CalculatorController) would
have had just a managed reference to the bean, plus the add() and
multiply() "action" methods.  In his example, his CalculatorController
contains the data plus the action methods.

So our faces-config.xml file would have looked like:

<faces-config>
        ...
        <managed-bean>
                <managed-bean-name>calcBean</managed-bean-name>
        
<managed-bean-class>com.arcmind.jsfquickstart.bean.CalculatorBean</manag
ed-bean-class>
                <managed-bean-scope>request</managed-bean-scope>
        </managed-bean>
        <managed-bean>
                <managed-bean-name>calcAction</managed-bean-name>
        
<managed-bean-class>com.arcmind.jsfquickstart.bean.CalculatorAction</man
aged-bean-class>
                <managed-bean-scope>request</managed-bean-scope>
                <managed-property>
                        <property-name>calcBean</property-name>
                        <value>#{calcBean}</value>
                </managed-property>
        </managed-bean>
        ...
</faces-config>

Our CalculatorBean would be a simple JavaBean containing firstNumber,
secondNumber, and result.
Our CalculatorAction class would have a field called calcBean (and its
getter and setter), which is set by JSF, plus the methods add() and
multiply().  (Note that, since the reference to calcBean is a managed
reference, CalculatorAction does *not* instantiate calculatorBean
itself.)

The JSP would then refer to #{calcBean.firstNumber},
#{calcBean.secondNumber}, #{calcBean.result}, #{calcAction.add}, and
#{calcAction.multiply}.

Either way works.  We just prefer the flexibility we see in separating
the data and actions.

- Brendan

-----Original Message-----
From: David Haynes [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, August 24, 2005 12:07 PM
To: MyFaces Discussion
Subject: Re: confusion on best practices in regard to a VO in
BackingBean


Rick Reumann wrote:

> On 8/23/05, *CONNER, BRENDAN (SBCSI)* <[EMAIL PROTECTED] 
> <mailto:[EMAIL PROTECTED]>> wrote:
>
>     As another alternative, the practice we've been following is to
>     have an
>     XyzAction class and a separate XyzBean class.  The Action class
has a
>     managed reference to the Bean class and has all the logic in it.
The
>     Bean class is just a straight JavaBean and contains all the data
>     needed
>     by the JSF page.
>
>
>
> Are you stating to register both as managed beans? Currently I do have

> two separate classes (XyzAction and XyzBean, but XyzBean is nested 
> inside the backing bean XyzAction). Using the approach above my 
> question is best illustrated by an example...
>
> In XyzAaction:
>
> XyzBean getXyz  {
>   return backendDelegate.getXyz();
> }
>  
> My question is how do I now refrence XyzBean from the JSP (using your 
> separate managed bean approach)?  If I do xyz.name <http://xyz.name>  
> how is it pulling the reference to getXyz? In other words, even if I 
> set XyzBean as a managed request scope bean how would this bean have 
> gotten set from the XyzAction in order to be available on the page? 
> I'm used to typical webapps where I stick stuff into the request from 
> servlets (actions in struts). In this scenario above I have not idea 
> how a separate managed XyzBean will be populated from a totally 
> separate managed bean?
>
> Can someone provide a concrete example of this usage? I'd love to see 
> a demo app with this approach. thanks.

Rick Hightower does this in his "Clearing the FUD about JSF" 
http://www-128.ibm.com/developerworks/java/library/j-jsf1/

He has the XyzBeand and XyzController with the controller containing:

XyzBean xyzBean = new XyzBean();

and then supporting the methods etc. via xyzBean.method() calls. His 
Controller is your Action.

See his extremely fine articles for more details.

-david-

Reply via email to