You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by un...@thorstenschaefer.de on 2007/01/07 21:52:48 UTC

[S2] How to separate Action from "FormBean"

I just took a look at the tutorials of Struts 2 today. As a Struts 1 user, I
don't like form beans that mostly copy your business data beans. In Struts 2,
you don't need form beans anymore, but the tutorial states that you have to
implement an execute() method into your business bean. Actually, what I would
prefer is an Action class, that just references the form bean, i.e., I can use
my business bean unchanged but only have to link them to an action. Is this
possible in Struts 2 and how do I achieve this? Further, is are there any
plans/release dates for a book on Struts 2?

Cheers,

Thorsten


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: [S2] How to separate Action from "FormBean"

Posted by Wesslan <fo...@wesslan.se>.
>To answer that part: not that I know of, but the existing WebWork in Action
from Manning is very good, and applies equally well to Struts 2 with minor
adjustments for package renaming etc.

Maybe it's time to create a web forum for Struts 2 and make a sticky thread
that says "Read Webwork in Action - it's a really good book for Struts 2!".
:)

Jokes aside, a web forum(like the one that Webwork has) would be great. Any
plans for that?

Cheers,
Peter

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: [S2] How to separate Action from "FormBean"

Posted by Laurie Harper <la...@holoweb.net>.
uni@thorstenschaefer.de wrote:
> Further, is are there any
> plans/release dates for a book on Struts 2?

To answer that part: not that I know of, but the existing WebWork in 
Action from Manning is very good, and applies equally well to Struts 2 
with minor adjustments for package renaming etc.

L.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: [S2] How to separate Action from "FormBean"

Posted by cilquirm <aa...@gmail.com>.


Dariusz Wojtas wrote:
> 
> Want to have a bean separate from the action and just reference it?
> Define your bean (whatever you want) and just declare it as a variable
> on your action.
> Nothing more.
> Add getter and setter.
> 
> class MyAction ... {
>    private MyBeanClass myBean;
> 
> }
> 
> in your JSP just prefix bean components with the bean name;
> 
>   <s:textfield name="myBean.title" ... />
> 
> That's all :)
> 
> Dariusz Wojtas
> 
> 


One other thing that's nice about Struts2/WW is that you can utilize the
ModelDriven interface on your action.

So your action is 

public class MyAction implements ModelDriven {

  private MyBean myBean = new MyBean();

  public Object getModel() { return myBean; }

}

that way your form fields can still be referenced by 

<s:textfield name="title" />

Also very useful when moving your properties from the action into a
model/domain object/value object/etc... because your front-end code does not
hae to change.

-- 
View this message in context: http://www.nabble.com/-S2--How-to-separate-Action-from-%22FormBean%22-tf2936107.html#a8222113
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: [S2] How to separate Action from "FormBean"

Posted by Dariusz Wojtas <dw...@gmail.com>.
I work with struts2 for about a month and it is perfectly stable.
The only 'issues' I could see were related to it's ajax support - but
it already works perfectly in most areas, and the issues being found
are quickly examined by the struts team.
It's definitely worth to try it.

It's simpler than S1 and has much more power.
But ... at the beginning you will spend some time even on simple things :)

Dariusz Wojtas

On 1/7/07, uni@thorstenschaefer.de <un...@thorstenschaefer.de> wrote:
> Dariusz Wojtas <dw...@gmail.com> wrote:
> > Want to have a bean separate from the action and just reference it?
> > Define your bean (whatever you want) and just declare it as a variable
> > on your action.
>
> Thanks Dariusz. That's exactly what I was looking for. Looks like I should
> definitely give S2 a try :)

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: [S2] How to separate Action from "FormBean"

Posted by un...@thorstenschaefer.de.
Dariusz Wojtas <dw...@gmail.com> wrote:
> Want to have a bean separate from the action and just reference it?
> Define your bean (whatever you want) and just declare it as a variable
> on your action.

Thanks Dariusz. That's exactly what I was looking for. Looks like I should
definitely give S2 a try :)


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: [S2] How to separate Action from "FormBean"

Posted by Dariusz Wojtas <dw...@gmail.com>.
Want to have a bean separate from the action and just reference it?
Define your bean (whatever you want) and just declare it as a variable
on your action.
Nothing more.
Add getter and setter.

class MyAction ... {
   private MyBeanClass myBean;

}

in your JSP just prefix bean components with the bean name;

  <s:textfield name="myBean.title" ... />

That's all :)

Dariusz Wojtas


On 1/7/07, uni@thorstenschaefer.de <un...@thorstenschaefer.de> wrote:
> I just took a look at the tutorials of Struts 2 today. As a Struts 1 user, I
> don't like form beans that mostly copy your business data beans. In Struts 2,
> you don't need form beans anymore, but the tutorial states that you have to
> implement an execute() method into your business bean. Actually, what I would
> prefer is an Action class, that just references the form bean, i.e., I can use
> my business bean unchanged but only have to link them to an action. Is this
> possible in Struts 2 and how do I achieve this? Further, is are there any
> plans/release dates for a book on Struts 2?
>
> Cheers,
>
> Thorsten

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org