You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Christian Grobmeier <gr...@gmail.com> on 2011/04/19 16:02:14 UTC

Recommended number of forms in one action

Hi,

this is question on best practice. It is: is it ok too let one Struts
Action handle two different forms?

For example:
Assume an Action called RegistrationAction. Its intention is to use it
for user registration.

The first form is a set of three properties for the registration itself;
the second one is a set of two properites containing an activation key
and the users mail address.

I am asking because it seems that validation is only allowed for one
set of properties. This indicates I should create two actions:

RegistrationAction
ActivationAction

But it seems a bit overloaded for only two methods.

Cheers,
Christian

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


Re: Recommended number of forms in one action

Posted by Christian Grobmeier <gr...@gmail.com>.
Truly an excellent answer from both of you guys.

It helped me recognize validation goes down to method level and I
learned about the wildcard methods.

In my example case, I will keep the two forms in one class. For future
development i will create more classes as I like this approach more

Cheers


On Tue, Apr 19, 2011 at 4:26 PM,  <st...@gmail.com> wrote:
> Great answer Eric!  I would also add that using wildcard methods for the
> express purpose of minimizing the number of actions you have is bad
> medicine.  I'm not suggesting you are, but I have seen this on client
> projects where they were  more interested in check-in/check-out of a single
> action than they were in doing the right thing.
>
> Peace,
> Scott
>
> On Tue, Apr 19, 2011 at 9:17 AM, Eric Lentz <Er...@sherwin.com> wrote:
>
>> > I am asking because it seems that validation is only allowed for one
>> > set of properties. This indicates I should create two actions
>>
>> Validation can go down to the method level and you can validate what you
>> desire for that method call. Just name the .xml file (if using that
>> approach) with the method name as well the class name.
>>
>> I would personally allow my decision on number of classes to be driven
>> based on class purpose. I try to limit classes to a finite set of
>> responsibilities, usually very fine-grained, in favor or more classes.
>> This provides easier reuse, unit testing, etc. When classes get to be big
>> and multi-purpose, then they get confusing and ripe for refactoring.
>>
>> If you feel you have a single purpose that a single class should address,
>> then use the one class. If you are serving multiple purposes that aren't
>> related (doesn't sound like your case), then don't worry about having just
>> a couple lines in a class. It is okay to have lots of classes.
>



-- 
http://www.grobmeier.de

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


Re: Recommended number of forms in one action

Posted by st...@gmail.com.
Great answer Eric!  I would also add that using wildcard methods for the
express purpose of minimizing the number of actions you have is bad
medicine.  I'm not suggesting you are, but I have seen this on client
projects where they were  more interested in check-in/check-out of a single
action than they were in doing the right thing.

Peace,
Scott

On Tue, Apr 19, 2011 at 9:17 AM, Eric Lentz <Er...@sherwin.com> wrote:

> > I am asking because it seems that validation is only allowed for one
> > set of properties. This indicates I should create two actions
>
> Validation can go down to the method level and you can validate what you
> desire for that method call. Just name the .xml file (if using that
> approach) with the method name as well the class name.
>
> I would personally allow my decision on number of classes to be driven
> based on class purpose. I try to limit classes to a finite set of
> responsibilities, usually very fine-grained, in favor or more classes.
> This provides easier reuse, unit testing, etc. When classes get to be big
> and multi-purpose, then they get confusing and ripe for refactoring.
>
> If you feel you have a single purpose that a single class should address,
> then use the one class. If you are serving multiple purposes that aren't
> related (doesn't sound like your case), then don't worry about having just
> a couple lines in a class. It is okay to have lots of classes.

Re: Recommended number of forms in one action

Posted by Eric Lentz <Er...@sherwin.com>.
> I am asking because it seems that validation is only allowed for one
> set of properties. This indicates I should create two actions

Validation can go down to the method level and you can validate what you 
desire for that method call. Just name the .xml file (if using that 
approach) with the method name as well the class name.

I would personally allow my decision on number of classes to be driven 
based on class purpose. I try to limit classes to a finite set of 
responsibilities, usually very fine-grained, in favor or more classes. 
This provides easier reuse, unit testing, etc. When classes get to be big 
and multi-purpose, then they get confusing and ripe for refactoring.

If you feel you have a single purpose that a single class should address, 
then use the one class. If you are serving multiple purposes that aren't 
related (doesn't sound like your case), then don't worry about having just 
a couple lines in a class. It is okay to have lots of classes.