You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Paul Barry <pa...@nyu.edu> on 2004/03/31 17:18:14 UTC

validator and dispatch action

Hello Everyone,

I am using the validator and dispatch actions and I am wonder what the 
best way to do this is.  Consider that I have the following method in a 
dispatch action:

add    - populates collections for drop-down lists, forwards to jsp page
create - needs to do validation and store in database
edit   - needs to populate form with the data to edit, forward to jsp page
update - needs to do validation and update database
delete - needs to delete a record from the database

You can see how the validation would be different for these actions. 
Let's say this is a dispatch action related to administrating users.  So 
for add, there would be no validation, it just gets the data need to 
build the form.  For create, there might be a password and verify 
password field that need to be validated, but update wouldn't have those 
fields.  Edit and delete would have to have a parameter for the primary 
key of the record to edit or delete.

Now I found something related at this link:

http://nagoya.apache.org/wiki/apachewiki.cgi?ValidatorDispatchAction

Which says to set validate to false in the struts-config.xml and then 
call validate method within each method of the dispatch action, like this:

ActionErrors errors = new ActionErrors();
errors = form.validate(mapping, request);

// Report any errors we have discovered back to the original form
if (!errors.isEmpty()) {
     saveErrors(request, errors);
     return  new ActionForward(mapping.getInput());
}

This seems like a really good solution to me, but there is one problem. 
  How do you call a different set of validation rules, based on which 
method you are in?  Doesn't this need to be something like this:

edit() {
     ActionErrors errors = new ActionErrors();
     errors = form.validateEdit(mapping, request);
}

update() {
     ActionErrors errors = new ActionErrors();
     errors = form.validateUpdate(mapping, request);
}

Because the rules for validating edit and update are different.  You 
could define different action-mappings in your struts config for each 
dispatch method, and then a form in your validation.xml for each 
action-mapping, where the form name is the same as the path property of 
the action-mapping, but doesn't this defeat the purpose of the dispatch 
action?  Why not just have separate actions at that point?  I think the 
answer is to just not use the dispatch action with the validator, but I 
wanted to know if others had found a way to do it.

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


Re: validator and dispatch action

Posted by Mike Foody <mi...@archangelpartners.com>.
Sorry about that link.  Frames are a killer ...

http://jakarta.apache.org/struts/api/org/apache/struts/actions/MappingDispatchAction.html


Mike Foody wrote:

> If you're not opposed to using 1.2 the MappingDispatchAction will 
> allow you to easily set up multiple action mappings, each capable of 
> having their own ActionForm, validation, etc and then actually handle 
> these all with a multiple methods in a single Action class. 
> http://jakarta.apache.org/struts/api/index.html
>
> Mike
>
> Paul Barry wrote:
>
>> Hello Everyone,
>>
>> I am using the validator and dispatch actions and I am wonder what 
>> the best way to do this is.  Consider that I have the following 
>> method in a dispatch action:
>>
>> add    - populates collections for drop-down lists, forwards to jsp page
>> create - needs to do validation and store in database
>> edit   - needs to populate form with the data to edit, forward to jsp 
>> page
>> update - needs to do validation and update database
>> delete - needs to delete a record from the database
>>
>> You can see how the validation would be different for these actions. 
>> Let's say this is a dispatch action related to administrating users.  
>> So for add, there would be no validation, it just gets the data need 
>> to build the form.  For create, there might be a password and verify 
>> password field that need to be validated, but update wouldn't have 
>> those fields.  Edit and delete would have to have a parameter for the 
>> primary key of the record to edit or delete.
>>
>> Now I found something related at this link:
>>
>> http://nagoya.apache.org/wiki/apachewiki.cgi?ValidatorDispatchAction
>>
>> Which says to set validate to false in the struts-config.xml and then 
>> call validate method within each method of the dispatch action, like 
>> this:
>>
>> ActionErrors errors = new ActionErrors();
>> errors = form.validate(mapping, request);
>>
>> // Report any errors we have discovered back to the original form
>> if (!errors.isEmpty()) {
>>     saveErrors(request, errors);
>>     return  new ActionForward(mapping.getInput());
>> }
>>
>> This seems like a really good solution to me, but there is one 
>> problem.  How do you call a different set of validation rules, based 
>> on which method you are in?  Doesn't this need to be something like 
>> this:
>>
>> edit() {
>>     ActionErrors errors = new ActionErrors();
>>     errors = form.validateEdit(mapping, request);
>> }
>>
>> update() {
>>     ActionErrors errors = new ActionErrors();
>>     errors = form.validateUpdate(mapping, request);
>> }
>>
>> Because the rules for validating edit and update are different.  You 
>> could define different action-mappings in your struts config for each 
>> dispatch method, and then a form in your validation.xml for each 
>> action-mapping, where the form name is the same as the path property 
>> of the action-mapping, but doesn't this defeat the purpose of the 
>> dispatch action?  Why not just have separate actions at that point?  
>> I think the answer is to just not use the dispatch action with the 
>> validator, but I wanted to know if others had found a way to do it.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org


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


Re: validator and dispatch action

Posted by Adam Hardy <ah...@cyberspaceroad.com>.
It depends on why you wanted to use dispatch action in the first place.

Yet another technique is to have multiple actions using the same action 
class, but with a seperate "parameter='whatever'" attribute, where 
'whatever' is 'update', 'delete' etc.

In fact you can put most common code in a base Action class, and in the 
subclass do the important bit. As long as the base class has a suitable 
switching / if else if clause, then you only need the one for the whole app.

HTH
Adam

On 03/31/2004 08:06 PM Paul Barry wrote:
> You could do this same thing in Strust 1.1, except that you would need 
> the method parameter.  In struts 1.1, the links would be:
> 
> /createSubscription.do?method=create
> /editSubscription.do?method=edit
> ...
> 
> And with MappingDispatchAction they would be
> 
> /createSubscription.do
> /editSubscription.do
> ...
> 
> That's a litte bit nicer, but if you are going to go through the trouble 
> of defining an action-mapping for each method, why not just skip the 
> dispatch aciton altogether and have separate actions?  If you keep all 
> related actions in a package together, is it any harder to manage?  I am 
> talking about having a configuration like this:
> 
> <action path="/createSubscription"
>           type="org.example.subscription.SubscriptionCreateAction">
>       <forward name="success" path="/editSubscription.jsp"/>
>   </action>
> 
>   <action path="/editSubscription"
>           type="org.example.subscription.SubscriptionEditAction">
>       <forward name="success" path="/editSubscription.jsp"/>
>   </action>
> 
>   <action path="/saveSubscription"
>           type="org.example.subscription.SubscriptionSaveAction"
>           name="subscriptionForm"
>           validate="true"
>           input="/editSubscription.jsp"
>           scope="request">
>       <forward name="success" path="/savedSubscription.jsp"/>
>   </action>
> 
>   <action path="/deleteSubscription"
>           type="org.example.subscription.SubscriptionDeleteAction"
>           name="subscriptionForm"
>           scope="request"
>           input="/subscription.jsp">
>       <forward name="success" path="/deletedSubscription.jsp"/>
>   </action>
> 
>   <action path="/listSubscriptions"
>           type="org.example.subscription.SubscriptionListAction">
>       <forward name="success" path="/subscriptionList.jsp"/>
>   </action>
> 
> 
> Mike Foody wrote:
> 
>> If you're not opposed to using 1.2 the MappingDispatchAction will 
>> allow you to easily set up multiple action mappings, each capable of 
>> having their own ActionForm, validation, etc and then actually handle 
>> these all with a multiple methods in a single Action class. 
>> http://jakarta.apache.org/struts/api/index.html
>>
>> Mike
>>
>> Paul Barry wrote:
>>
>>> Hello Everyone,
>>>
>>> I am using the validator and dispatch actions and I am wonder what 
>>> the best way to do this is.  Consider that I have the following 
>>> method in a dispatch action:
>>>
>>> add    - populates collections for drop-down lists, forwards to jsp page
>>> create - needs to do validation and store in database
>>> edit   - needs to populate form with the data to edit, forward to jsp 
>>> page
>>> update - needs to do validation and update database
>>> delete - needs to delete a record from the database
>>>
>>> You can see how the validation would be different for these actions. 
>>> Let's say this is a dispatch action related to administrating users.  
>>> So for add, there would be no validation, it just gets the data need 
>>> to build the form.  For create, there might be a password and verify 
>>> password field that need to be validated, but update wouldn't have 
>>> those fields.  Edit and delete would have to have a parameter for the 
>>> primary key of the record to edit or delete.
>>>
>>> Now I found something related at this link:
>>>
>>> http://nagoya.apache.org/wiki/apachewiki.cgi?ValidatorDispatchAction
>>>
>>> Which says to set validate to false in the struts-config.xml and then 
>>> call validate method within each method of the dispatch action, like 
>>> this:
>>>
>>> ActionErrors errors = new ActionErrors();
>>> errors = form.validate(mapping, request);
>>>
>>> // Report any errors we have discovered back to the original form
>>> if (!errors.isEmpty()) {
>>>     saveErrors(request, errors);
>>>     return  new ActionForward(mapping.getInput());
>>> }
>>>
>>> This seems like a really good solution to me, but there is one 
>>> problem.  How do you call a different set of validation rules, based 
>>> on which method you are in?  Doesn't this need to be something like 
>>> this:
>>>
>>> edit() {
>>>     ActionErrors errors = new ActionErrors();
>>>     errors = form.validateEdit(mapping, request);
>>> }
>>>
>>> update() {
>>>     ActionErrors errors = new ActionErrors();
>>>     errors = form.validateUpdate(mapping, request);
>>> }
>>>
>>> Because the rules for validating edit and update are different.  You 
>>> could define different action-mappings in your struts config for each 
>>> dispatch method, and then a form in your validation.xml for each 
>>> action-mapping, where the form name is the same as the path property 
>>> of the action-mapping, but doesn't this defeat the purpose of the 
>>> dispatch action?  Why not just have separate actions at that point?  
>>> I think the answer is to just not use the dispatch action with the 
>>> validator, but I wanted to know if others had found a way to do it.
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 


-- 
struts 1.1 + tomcat 5.0.16 + java 1.4.2
Linux 2.4.20 Debian


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


Re: validator and dispatch action

Posted by Mike Foody <mi...@archangelpartners.com>.
Agreed about it being mostly syntactical sugar. 

On the other hand I think defining multiple mappings for the same Action 
is extremely useful.  It allows you to group your functionality and 
easily access shared functionality, but also provide alternative 
validation and forwards without having work around it in the Action 
class.  It certainly isn't providing  anything you couldn't otherwise 
but from my perspective seems a cleaner solution.



Paul Barry wrote:

> You could do this same thing in Strust 1.1, except that you would need 
> the method parameter.  In struts 1.1, the links would be:
>
> /createSubscription.do?method=create
> /editSubscription.do?method=edit
> ...
>
> And with MappingDispatchAction they would be
>
> /createSubscription.do
> /editSubscription.do
> ...
>
> That's a litte bit nicer, but if you are going to go through the 
> trouble of defining an action-mapping for each method, why not just 
> skip the dispatch aciton altogether and have separate actions?  If you 
> keep all related actions in a package together, is it any harder to 
> manage?  I am talking about having a configuration like this:
>
> <action path="/createSubscription"
>           type="org.example.subscription.SubscriptionCreateAction">
>       <forward name="success" path="/editSubscription.jsp"/>
>   </action>
>
>   <action path="/editSubscription"
>           type="org.example.subscription.SubscriptionEditAction">
>       <forward name="success" path="/editSubscription.jsp"/>
>   </action>
>
>   <action path="/saveSubscription"
>           type="org.example.subscription.SubscriptionSaveAction"
>           name="subscriptionForm"
>           validate="true"
>           input="/editSubscription.jsp"
>           scope="request">
>       <forward name="success" path="/savedSubscription.jsp"/>
>   </action>
>
>   <action path="/deleteSubscription"
>           type="org.example.subscription.SubscriptionDeleteAction"
>           name="subscriptionForm"
>           scope="request"
>           input="/subscription.jsp">
>       <forward name="success" path="/deletedSubscription.jsp"/>
>   </action>
>
>   <action path="/listSubscriptions"
>           type="org.example.subscription.SubscriptionListAction">
>       <forward name="success" path="/subscriptionList.jsp"/>
>   </action>
>
>
> Mike Foody wrote:
>
>> If you're not opposed to using 1.2 the MappingDispatchAction will 
>> allow you to easily set up multiple action mappings, each capable of 
>> having their own ActionForm, validation, etc and then actually handle 
>> these all with a multiple methods in a single Action class. 
>> http://jakarta.apache.org/struts/api/index.html
>>
>> Mike
>>
>> Paul Barry wrote:
>>
>>> Hello Everyone,
>>>
>>> I am using the validator and dispatch actions and I am wonder what 
>>> the best way to do this is.  Consider that I have the following 
>>> method in a dispatch action:
>>>
>>> add    - populates collections for drop-down lists, forwards to jsp 
>>> page
>>> create - needs to do validation and store in database
>>> edit   - needs to populate form with the data to edit, forward to 
>>> jsp page
>>> update - needs to do validation and update database
>>> delete - needs to delete a record from the database
>>>
>>> You can see how the validation would be different for these actions. 
>>> Let's say this is a dispatch action related to administrating 
>>> users.  So for add, there would be no validation, it just gets the 
>>> data need to build the form.  For create, there might be a password 
>>> and verify password field that need to be validated, but update 
>>> wouldn't have those fields.  Edit and delete would have to have a 
>>> parameter for the primary key of the record to edit or delete.
>>>
>>> Now I found something related at this link:
>>>
>>> http://nagoya.apache.org/wiki/apachewiki.cgi?ValidatorDispatchAction
>>>
>>> Which says to set validate to false in the struts-config.xml and 
>>> then call validate method within each method of the dispatch action, 
>>> like this:
>>>
>>> ActionErrors errors = new ActionErrors();
>>> errors = form.validate(mapping, request);
>>>
>>> // Report any errors we have discovered back to the original form
>>> if (!errors.isEmpty()) {
>>>     saveErrors(request, errors);
>>>     return  new ActionForward(mapping.getInput());
>>> }
>>>
>>> This seems like a really good solution to me, but there is one 
>>> problem.  How do you call a different set of validation rules, based 
>>> on which method you are in?  Doesn't this need to be something like 
>>> this:
>>>
>>> edit() {
>>>     ActionErrors errors = new ActionErrors();
>>>     errors = form.validateEdit(mapping, request);
>>> }
>>>
>>> update() {
>>>     ActionErrors errors = new ActionErrors();
>>>     errors = form.validateUpdate(mapping, request);
>>> }
>>>
>>> Because the rules for validating edit and update are different.  You 
>>> could define different action-mappings in your struts config for 
>>> each dispatch method, and then a form in your validation.xml for 
>>> each action-mapping, where the form name is the same as the path 
>>> property of the action-mapping, but doesn't this defeat the purpose 
>>> of the dispatch action?  Why not just have separate actions at that 
>>> point?  I think the answer is to just not use the dispatch action 
>>> with the validator, but I wanted to know if others had found a way 
>>> to do it.
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org


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


Re: validator and dispatch action

Posted by Paul Barry <pa...@nyu.edu>.
You could do this same thing in Strust 1.1, except that you would need 
the method parameter.  In struts 1.1, the links would be:

/createSubscription.do?method=create
/editSubscription.do?method=edit
...

And with MappingDispatchAction they would be

/createSubscription.do
/editSubscription.do
...

That's a litte bit nicer, but if you are going to go through the trouble 
of defining an action-mapping for each method, why not just skip the 
dispatch aciton altogether and have separate actions?  If you keep all 
related actions in a package together, is it any harder to manage?  I am 
talking about having a configuration like this:

<action path="/createSubscription"
           type="org.example.subscription.SubscriptionCreateAction">
       <forward name="success" path="/editSubscription.jsp"/>
   </action>

   <action path="/editSubscription"
           type="org.example.subscription.SubscriptionEditAction">
       <forward name="success" path="/editSubscription.jsp"/>
   </action>

   <action path="/saveSubscription"
           type="org.example.subscription.SubscriptionSaveAction"
           name="subscriptionForm"
           validate="true"
           input="/editSubscription.jsp"
           scope="request">
       <forward name="success" path="/savedSubscription.jsp"/>
   </action>

   <action path="/deleteSubscription"
           type="org.example.subscription.SubscriptionDeleteAction"
           name="subscriptionForm"
           scope="request"
           input="/subscription.jsp">
       <forward name="success" path="/deletedSubscription.jsp"/>
   </action>

   <action path="/listSubscriptions"
           type="org.example.subscription.SubscriptionListAction">
       <forward name="success" path="/subscriptionList.jsp"/>
   </action>


Mike Foody wrote:

> If you're not opposed to using 1.2 the MappingDispatchAction will allow 
> you to easily set up multiple action mappings, each capable of having 
> their own ActionForm, validation, etc and then actually handle these all 
> with a multiple methods in a single Action class. 
> http://jakarta.apache.org/struts/api/index.html
> 
> Mike
> 
> Paul Barry wrote:
> 
>> Hello Everyone,
>>
>> I am using the validator and dispatch actions and I am wonder what the 
>> best way to do this is.  Consider that I have the following method in 
>> a dispatch action:
>>
>> add    - populates collections for drop-down lists, forwards to jsp page
>> create - needs to do validation and store in database
>> edit   - needs to populate form with the data to edit, forward to jsp 
>> page
>> update - needs to do validation and update database
>> delete - needs to delete a record from the database
>>
>> You can see how the validation would be different for these actions. 
>> Let's say this is a dispatch action related to administrating users.  
>> So for add, there would be no validation, it just gets the data need 
>> to build the form.  For create, there might be a password and verify 
>> password field that need to be validated, but update wouldn't have 
>> those fields.  Edit and delete would have to have a parameter for the 
>> primary key of the record to edit or delete.
>>
>> Now I found something related at this link:
>>
>> http://nagoya.apache.org/wiki/apachewiki.cgi?ValidatorDispatchAction
>>
>> Which says to set validate to false in the struts-config.xml and then 
>> call validate method within each method of the dispatch action, like 
>> this:
>>
>> ActionErrors errors = new ActionErrors();
>> errors = form.validate(mapping, request);
>>
>> // Report any errors we have discovered back to the original form
>> if (!errors.isEmpty()) {
>>     saveErrors(request, errors);
>>     return  new ActionForward(mapping.getInput());
>> }
>>
>> This seems like a really good solution to me, but there is one 
>> problem.  How do you call a different set of validation rules, based 
>> on which method you are in?  Doesn't this need to be something like this:
>>
>> edit() {
>>     ActionErrors errors = new ActionErrors();
>>     errors = form.validateEdit(mapping, request);
>> }
>>
>> update() {
>>     ActionErrors errors = new ActionErrors();
>>     errors = form.validateUpdate(mapping, request);
>> }
>>
>> Because the rules for validating edit and update are different.  You 
>> could define different action-mappings in your struts config for each 
>> dispatch method, and then a form in your validation.xml for each 
>> action-mapping, where the form name is the same as the path property 
>> of the action-mapping, but doesn't this defeat the purpose of the 
>> dispatch action?  Why not just have separate actions at that point?  I 
>> think the answer is to just not use the dispatch action with the 
>> validator, but I wanted to know if others had found a way to do it.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 

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


Re: validator and dispatch action

Posted by Mike Foody <mi...@archangelpartners.com>.
If you're not opposed to using 1.2 the MappingDispatchAction will allow 
you to easily set up multiple action mappings, each capable of having 
their own ActionForm, validation, etc and then actually handle these all 
with a multiple methods in a single Action class.  

http://jakarta.apache.org/struts/api/index.html

Mike

Paul Barry wrote:

> Hello Everyone,
>
> I am using the validator and dispatch actions and I am wonder what the 
> best way to do this is.  Consider that I have the following method in 
> a dispatch action:
>
> add    - populates collections for drop-down lists, forwards to jsp page
> create - needs to do validation and store in database
> edit   - needs to populate form with the data to edit, forward to jsp 
> page
> update - needs to do validation and update database
> delete - needs to delete a record from the database
>
> You can see how the validation would be different for these actions. 
> Let's say this is a dispatch action related to administrating users.  
> So for add, there would be no validation, it just gets the data need 
> to build the form.  For create, there might be a password and verify 
> password field that need to be validated, but update wouldn't have 
> those fields.  Edit and delete would have to have a parameter for the 
> primary key of the record to edit or delete.
>
> Now I found something related at this link:
>
> http://nagoya.apache.org/wiki/apachewiki.cgi?ValidatorDispatchAction
>
> Which says to set validate to false in the struts-config.xml and then 
> call validate method within each method of the dispatch action, like 
> this:
>
> ActionErrors errors = new ActionErrors();
> errors = form.validate(mapping, request);
>
> // Report any errors we have discovered back to the original form
> if (!errors.isEmpty()) {
>     saveErrors(request, errors);
>     return  new ActionForward(mapping.getInput());
> }
>
> This seems like a really good solution to me, but there is one 
> problem.  How do you call a different set of validation rules, based 
> on which method you are in?  Doesn't this need to be something like this:
>
> edit() {
>     ActionErrors errors = new ActionErrors();
>     errors = form.validateEdit(mapping, request);
> }
>
> update() {
>     ActionErrors errors = new ActionErrors();
>     errors = form.validateUpdate(mapping, request);
> }
>
> Because the rules for validating edit and update are different.  You 
> could define different action-mappings in your struts config for each 
> dispatch method, and then a form in your validation.xml for each 
> action-mapping, where the form name is the same as the path property 
> of the action-mapping, but doesn't this defeat the purpose of the 
> dispatch action?  Why not just have separate actions at that point?  I 
> think the answer is to just not use the dispatch action with the 
> validator, but I wanted to know if others had found a way to do it.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org


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


Re: validator and dispatch action

Posted by Paul Barry <pa...@nyu.edu>.
I get this exception:

javax.servlet.ServletException: Configuration is frozen

Adam Hardy wrote:

> I mean, try changing it in the code in your action when you want to 
> validate, & change it back afterwards to its previous value when done. 
> Is that what you tried?
> 
> String oldName = mapping.getName();
> mapping.setName("widget-edit");
> form.validate(mapping, request);
> mapping.setName(oldName);
> 
> 
> 
> On 03/31/2004 05:52 PM Paul Barry wrote:
> 
>> The name of the action-mapping has to correspond to the name of the 
>> form-bean.
>>
>> Adam Hardy wrote:
>>
>>> If I really wanted to stick with your set-up, I see a way it might be 
>>> possible, although I have not done this myself.
>>>
>>> Try changing the 'name' attribute of the mapping to the validation 
>>> that you defined in the validation.xml, e.g. 'widget-update' or 
>>> 'widget-edit' and then call the validate() method.
>>>
>>> My main worry is that ActionMapping may not like being changed, but 
>>> if so, you could instantiate a new one.
>>>
>>> Adam
>>>
>>> On 03/31/2004 05:18 PM Paul Barry wrote:
>>>
>>>> Hello Everyone,
>>>>
>>>> I am using the validator and dispatch actions and I am wonder what 
>>>> the best way to do this is.  Consider that I have the following 
>>>> method in a dispatch action:
>>>>
>>>> add    - populates collections for drop-down lists, forwards to jsp 
>>>> page
>>>> create - needs to do validation and store in database
>>>> edit   - needs to populate form with the data to edit, forward to 
>>>> jsp page
>>>> update - needs to do validation and update database
>>>> delete - needs to delete a record from the database
>>>>
>>>> You can see how the validation would be different for these actions. 
>>>> Let's say this is a dispatch action related to administrating 
>>>> users.  So for add, there would be no validation, it just gets the 
>>>> data need to build the form.  For create, there might be a password 
>>>> and verify password field that need to be validated, but update 
>>>> wouldn't have those fields.  Edit and delete would have to have a 
>>>> parameter for the primary key of the record to edit or delete.
>>>>
>>>> Now I found something related at this link:
>>>>
>>>> http://nagoya.apache.org/wiki/apachewiki.cgi?ValidatorDispatchAction
>>>>
>>>> Which says to set validate to false in the struts-config.xml and 
>>>> then call validate method within each method of the dispatch action, 
>>>> like this:
>>>>
>>>> ActionErrors errors = new ActionErrors();
>>>> errors = form.validate(mapping, request);
>>>>
>>>> // Report any errors we have discovered back to the original form
>>>> if (!errors.isEmpty()) {
>>>>     saveErrors(request, errors);
>>>>     return  new ActionForward(mapping.getInput());
>>>> }
>>>>
>>>> This seems like a really good solution to me, but there is one 
>>>> problem.  How do you call a different set of validation rules, based 
>>>> on which method you are in?  Doesn't this need to be something like 
>>>> this:
>>>>
>>>> edit() {
>>>>     ActionErrors errors = new ActionErrors();
>>>>     errors = form.validateEdit(mapping, request);
>>>> }
>>>>
>>>> update() {
>>>>     ActionErrors errors = new ActionErrors();
>>>>     errors = form.validateUpdate(mapping, request);
>>>> }
>>>>
>>>> Because the rules for validating edit and update are different.  You 
>>>> could define different action-mappings in your struts config for 
>>>> each dispatch method, and then a form in your validation.xml for 
>>>> each action-mapping, where the form name is the same as the path 
>>>> property of the action-mapping, but doesn't this defeat the purpose 
>>>> of the dispatch action?  Why not just have separate actions at that 
>>>> point?  I think the answer is to just not use the dispatch action 
>>>> with the validator, but I wanted to know if others had found a way 
>>>> to do it.
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>>> For additional commands, e-mail: user-help@struts.apache.org
>>>>
>>>>
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
> 
> 

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


Re: validator and dispatch action

Posted by Paul Barry <pa...@nyu.edu>.
Ah, I got you now.  No, I didn't try that, I will give it a try.

Adam Hardy wrote:

> I mean, try changing it in the code in your action when you want to 
> validate, & change it back afterwards to its previous value when done. 
> Is that what you tried?
> 
> String oldName = mapping.getName();
> mapping.setName("widget-edit");
> form.validate(mapping, request);
> mapping.setName(oldName);
> 
> 
> 
> On 03/31/2004 05:52 PM Paul Barry wrote:
> 
>> The name of the action-mapping has to correspond to the name of the 
>> form-bean.
>>
>> Adam Hardy wrote:
>>
>>> If I really wanted to stick with your set-up, I see a way it might be 
>>> possible, although I have not done this myself.
>>>
>>> Try changing the 'name' attribute of the mapping to the validation 
>>> that you defined in the validation.xml, e.g. 'widget-update' or 
>>> 'widget-edit' and then call the validate() method.
>>>
>>> My main worry is that ActionMapping may not like being changed, but 
>>> if so, you could instantiate a new one.
>>>
>>> Adam
>>>
>>> On 03/31/2004 05:18 PM Paul Barry wrote:
>>>
>>>> Hello Everyone,
>>>>
>>>> I am using the validator and dispatch actions and I am wonder what 
>>>> the best way to do this is.  Consider that I have the following 
>>>> method in a dispatch action:
>>>>
>>>> add    - populates collections for drop-down lists, forwards to jsp 
>>>> page
>>>> create - needs to do validation and store in database
>>>> edit   - needs to populate form with the data to edit, forward to 
>>>> jsp page
>>>> update - needs to do validation and update database
>>>> delete - needs to delete a record from the database
>>>>
>>>> You can see how the validation would be different for these actions. 
>>>> Let's say this is a dispatch action related to administrating 
>>>> users.  So for add, there would be no validation, it just gets the 
>>>> data need to build the form.  For create, there might be a password 
>>>> and verify password field that need to be validated, but update 
>>>> wouldn't have those fields.  Edit and delete would have to have a 
>>>> parameter for the primary key of the record to edit or delete.
>>>>
>>>> Now I found something related at this link:
>>>>
>>>> http://nagoya.apache.org/wiki/apachewiki.cgi?ValidatorDispatchAction
>>>>
>>>> Which says to set validate to false in the struts-config.xml and 
>>>> then call validate method within each method of the dispatch action, 
>>>> like this:
>>>>
>>>> ActionErrors errors = new ActionErrors();
>>>> errors = form.validate(mapping, request);
>>>>
>>>> // Report any errors we have discovered back to the original form
>>>> if (!errors.isEmpty()) {
>>>>     saveErrors(request, errors);
>>>>     return  new ActionForward(mapping.getInput());
>>>> }
>>>>
>>>> This seems like a really good solution to me, but there is one 
>>>> problem.  How do you call a different set of validation rules, based 
>>>> on which method you are in?  Doesn't this need to be something like 
>>>> this:
>>>>
>>>> edit() {
>>>>     ActionErrors errors = new ActionErrors();
>>>>     errors = form.validateEdit(mapping, request);
>>>> }
>>>>
>>>> update() {
>>>>     ActionErrors errors = new ActionErrors();
>>>>     errors = form.validateUpdate(mapping, request);
>>>> }
>>>>
>>>> Because the rules for validating edit and update are different.  You 
>>>> could define different action-mappings in your struts config for 
>>>> each dispatch method, and then a form in your validation.xml for 
>>>> each action-mapping, where the form name is the same as the path 
>>>> property of the action-mapping, but doesn't this defeat the purpose 
>>>> of the dispatch action?  Why not just have separate actions at that 
>>>> point?  I think the answer is to just not use the dispatch action 
>>>> with the validator, but I wanted to know if others had found a way 
>>>> to do it.
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>>> For additional commands, e-mail: user-help@struts.apache.org
>>>>
>>>>
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
> 
> 

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


RE: validator and dispatch action

Posted by Marco Mistroni <mm...@waersystems.com>.
Hi,
	Although not using validator, I had similar problem
When using dispatch actions (different methods requires different
Validations).
So I enable always validation, but I wrote my custom validate method
In the ActionForm.
Now, if u want to use validator, first thing that comes to my mind
Would be to use validator for what all your methods have in common,
And then write a custom validate() method that checks which 'method'
Is going to be called, and depending on that you will validate or
Do nothing.

My 2 cents..

Regards
	marco

-----Original Message-----
From: Adam Hardy [mailto:ahardy.struts@cyberspaceroad.com] 
Sent: 31 March 2004 17:13
To: Struts Users Mailing List
Subject: Re: validator and dispatch action

I mean, try changing it in the code in your action when you want to 
validate, & change it back afterwards to its previous value when done. 
Is that what you tried?

String oldName = mapping.getName();
mapping.setName("widget-edit");
form.validate(mapping, request);
mapping.setName(oldName);



On 03/31/2004 05:52 PM Paul Barry wrote:
> The name of the action-mapping has to correspond to the name of the 
> form-bean.
> 
> Adam Hardy wrote:
> 
>> If I really wanted to stick with your set-up, I see a way it might be

>> possible, although I have not done this myself.
>>
>> Try changing the 'name' attribute of the mapping to the validation 
>> that you defined in the validation.xml, e.g. 'widget-update' or 
>> 'widget-edit' and then call the validate() method.
>>
>> My main worry is that ActionMapping may not like being changed, but
if 
>> so, you could instantiate a new one.
>>
>> Adam
>>
>> On 03/31/2004 05:18 PM Paul Barry wrote:
>>
>>> Hello Everyone,
>>>
>>> I am using the validator and dispatch actions and I am wonder what 
>>> the best way to do this is.  Consider that I have the following 
>>> method in a dispatch action:
>>>
>>> add    - populates collections for drop-down lists, forwards to jsp
page
>>> create - needs to do validation and store in database
>>> edit   - needs to populate form with the data to edit, forward to
jsp 
>>> page
>>> update - needs to do validation and update database
>>> delete - needs to delete a record from the database
>>>
>>> You can see how the validation would be different for these actions.

>>> Let's say this is a dispatch action related to administrating users.

>>> So for add, there would be no validation, it just gets the data need

>>> to build the form.  For create, there might be a password and verify

>>> password field that need to be validated, but update wouldn't have 
>>> those fields.  Edit and delete would have to have a parameter for
the 
>>> primary key of the record to edit or delete.
>>>
>>> Now I found something related at this link:
>>>
>>> http://nagoya.apache.org/wiki/apachewiki.cgi?ValidatorDispatchAction
>>>
>>> Which says to set validate to false in the struts-config.xml and
then 
>>> call validate method within each method of the dispatch action, like

>>> this:
>>>
>>> ActionErrors errors = new ActionErrors();
>>> errors = form.validate(mapping, request);
>>>
>>> // Report any errors we have discovered back to the original form
>>> if (!errors.isEmpty()) {
>>>     saveErrors(request, errors);
>>>     return  new ActionForward(mapping.getInput());
>>> }
>>>
>>> This seems like a really good solution to me, but there is one 
>>> problem.  How do you call a different set of validation rules, based

>>> on which method you are in?  Doesn't this need to be something like 
>>> this:
>>>
>>> edit() {
>>>     ActionErrors errors = new ActionErrors();
>>>     errors = form.validateEdit(mapping, request);
>>> }
>>>
>>> update() {
>>>     ActionErrors errors = new ActionErrors();
>>>     errors = form.validateUpdate(mapping, request);
>>> }
>>>
>>> Because the rules for validating edit and update are different.  You

>>> could define different action-mappings in your struts config for
each 
>>> dispatch method, and then a form in your validation.xml for each 
>>> action-mapping, where the form name is the same as the path property

>>> of the action-mapping, but doesn't this defeat the purpose of the 
>>> dispatch action?  Why not just have separate actions at that point?

>>> I think the answer is to just not use the dispatch action with the 
>>> validator, but I wanted to know if others had found a way to do it.
>>>
>>>
---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>> For additional commands, e-mail: user-help@struts.apache.org
>>>
>>>
>>
>>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 


-- 
struts 1.1 + tomcat 5.0.16 + java 1.4.2
Linux 2.4.20 Debian


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


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


Re: validator and dispatch action

Posted by Adam Hardy <ah...@cyberspaceroad.com>.
I mean, try changing it in the code in your action when you want to 
validate, & change it back afterwards to its previous value when done. 
Is that what you tried?

String oldName = mapping.getName();
mapping.setName("widget-edit");
form.validate(mapping, request);
mapping.setName(oldName);



On 03/31/2004 05:52 PM Paul Barry wrote:
> The name of the action-mapping has to correspond to the name of the 
> form-bean.
> 
> Adam Hardy wrote:
> 
>> If I really wanted to stick with your set-up, I see a way it might be 
>> possible, although I have not done this myself.
>>
>> Try changing the 'name' attribute of the mapping to the validation 
>> that you defined in the validation.xml, e.g. 'widget-update' or 
>> 'widget-edit' and then call the validate() method.
>>
>> My main worry is that ActionMapping may not like being changed, but if 
>> so, you could instantiate a new one.
>>
>> Adam
>>
>> On 03/31/2004 05:18 PM Paul Barry wrote:
>>
>>> Hello Everyone,
>>>
>>> I am using the validator and dispatch actions and I am wonder what 
>>> the best way to do this is.  Consider that I have the following 
>>> method in a dispatch action:
>>>
>>> add    - populates collections for drop-down lists, forwards to jsp page
>>> create - needs to do validation and store in database
>>> edit   - needs to populate form with the data to edit, forward to jsp 
>>> page
>>> update - needs to do validation and update database
>>> delete - needs to delete a record from the database
>>>
>>> You can see how the validation would be different for these actions. 
>>> Let's say this is a dispatch action related to administrating users.  
>>> So for add, there would be no validation, it just gets the data need 
>>> to build the form.  For create, there might be a password and verify 
>>> password field that need to be validated, but update wouldn't have 
>>> those fields.  Edit and delete would have to have a parameter for the 
>>> primary key of the record to edit or delete.
>>>
>>> Now I found something related at this link:
>>>
>>> http://nagoya.apache.org/wiki/apachewiki.cgi?ValidatorDispatchAction
>>>
>>> Which says to set validate to false in the struts-config.xml and then 
>>> call validate method within each method of the dispatch action, like 
>>> this:
>>>
>>> ActionErrors errors = new ActionErrors();
>>> errors = form.validate(mapping, request);
>>>
>>> // Report any errors we have discovered back to the original form
>>> if (!errors.isEmpty()) {
>>>     saveErrors(request, errors);
>>>     return  new ActionForward(mapping.getInput());
>>> }
>>>
>>> This seems like a really good solution to me, but there is one 
>>> problem.  How do you call a different set of validation rules, based 
>>> on which method you are in?  Doesn't this need to be something like 
>>> this:
>>>
>>> edit() {
>>>     ActionErrors errors = new ActionErrors();
>>>     errors = form.validateEdit(mapping, request);
>>> }
>>>
>>> update() {
>>>     ActionErrors errors = new ActionErrors();
>>>     errors = form.validateUpdate(mapping, request);
>>> }
>>>
>>> Because the rules for validating edit and update are different.  You 
>>> could define different action-mappings in your struts config for each 
>>> dispatch method, and then a form in your validation.xml for each 
>>> action-mapping, where the form name is the same as the path property 
>>> of the action-mapping, but doesn't this defeat the purpose of the 
>>> dispatch action?  Why not just have separate actions at that point?  
>>> I think the answer is to just not use the dispatch action with the 
>>> validator, but I wanted to know if others had found a way to do it.
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>> For additional commands, e-mail: user-help@struts.apache.org
>>>
>>>
>>
>>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 


-- 
struts 1.1 + tomcat 5.0.16 + java 1.4.2
Linux 2.4.20 Debian


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


Re: validator and dispatch action

Posted by Paul Barry <pa...@nyu.edu>.
The name of the action-mapping has to correspond to the name of the 
form-bean.

Adam Hardy wrote:

> If I really wanted to stick with your set-up, I see a way it might be 
> possible, although I have not done this myself.
> 
> Try changing the 'name' attribute of the mapping to the validation that 
> you defined in the validation.xml, e.g. 'widget-update' or 'widget-edit' 
> and then call the validate() method.
> 
> My main worry is that ActionMapping may not like being changed, but if 
> so, you could instantiate a new one.
> 
> Adam
> 
> On 03/31/2004 05:18 PM Paul Barry wrote:
> 
>> Hello Everyone,
>>
>> I am using the validator and dispatch actions and I am wonder what the 
>> best way to do this is.  Consider that I have the following method in 
>> a dispatch action:
>>
>> add    - populates collections for drop-down lists, forwards to jsp page
>> create - needs to do validation and store in database
>> edit   - needs to populate form with the data to edit, forward to jsp 
>> page
>> update - needs to do validation and update database
>> delete - needs to delete a record from the database
>>
>> You can see how the validation would be different for these actions. 
>> Let's say this is a dispatch action related to administrating users.  
>> So for add, there would be no validation, it just gets the data need 
>> to build the form.  For create, there might be a password and verify 
>> password field that need to be validated, but update wouldn't have 
>> those fields.  Edit and delete would have to have a parameter for the 
>> primary key of the record to edit or delete.
>>
>> Now I found something related at this link:
>>
>> http://nagoya.apache.org/wiki/apachewiki.cgi?ValidatorDispatchAction
>>
>> Which says to set validate to false in the struts-config.xml and then 
>> call validate method within each method of the dispatch action, like 
>> this:
>>
>> ActionErrors errors = new ActionErrors();
>> errors = form.validate(mapping, request);
>>
>> // Report any errors we have discovered back to the original form
>> if (!errors.isEmpty()) {
>>     saveErrors(request, errors);
>>     return  new ActionForward(mapping.getInput());
>> }
>>
>> This seems like a really good solution to me, but there is one 
>> problem.  How do you call a different set of validation rules, based 
>> on which method you are in?  Doesn't this need to be something like this:
>>
>> edit() {
>>     ActionErrors errors = new ActionErrors();
>>     errors = form.validateEdit(mapping, request);
>> }
>>
>> update() {
>>     ActionErrors errors = new ActionErrors();
>>     errors = form.validateUpdate(mapping, request);
>> }
>>
>> Because the rules for validating edit and update are different.  You 
>> could define different action-mappings in your struts config for each 
>> dispatch method, and then a form in your validation.xml for each 
>> action-mapping, where the form name is the same as the path property 
>> of the action-mapping, but doesn't this defeat the purpose of the 
>> dispatch action?  Why not just have separate actions at that point?  I 
>> think the answer is to just not use the dispatch action with the 
>> validator, but I wanted to know if others had found a way to do it.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
> 
> 

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


Re: validator and dispatch action

Posted by Adam Hardy <ah...@cyberspaceroad.com>.
If I really wanted to stick with your set-up, I see a way it might be 
possible, although I have not done this myself.

Try changing the 'name' attribute of the mapping to the validation that 
you defined in the validation.xml, e.g. 'widget-update' or 'widget-edit' 
and then call the validate() method.

My main worry is that ActionMapping may not like being changed, but if 
so, you could instantiate a new one.

Adam

On 03/31/2004 05:18 PM Paul Barry wrote:
> Hello Everyone,
> 
> I am using the validator and dispatch actions and I am wonder what the 
> best way to do this is.  Consider that I have the following method in a 
> dispatch action:
> 
> add    - populates collections for drop-down lists, forwards to jsp page
> create - needs to do validation and store in database
> edit   - needs to populate form with the data to edit, forward to jsp page
> update - needs to do validation and update database
> delete - needs to delete a record from the database
> 
> You can see how the validation would be different for these actions. 
> Let's say this is a dispatch action related to administrating users.  So 
> for add, there would be no validation, it just gets the data need to 
> build the form.  For create, there might be a password and verify 
> password field that need to be validated, but update wouldn't have those 
> fields.  Edit and delete would have to have a parameter for the primary 
> key of the record to edit or delete.
> 
> Now I found something related at this link:
> 
> http://nagoya.apache.org/wiki/apachewiki.cgi?ValidatorDispatchAction
> 
> Which says to set validate to false in the struts-config.xml and then 
> call validate method within each method of the dispatch action, like this:
> 
> ActionErrors errors = new ActionErrors();
> errors = form.validate(mapping, request);
> 
> // Report any errors we have discovered back to the original form
> if (!errors.isEmpty()) {
>     saveErrors(request, errors);
>     return  new ActionForward(mapping.getInput());
> }
> 
> This seems like a really good solution to me, but there is one problem. 
>  How do you call a different set of validation rules, based on which 
> method you are in?  Doesn't this need to be something like this:
> 
> edit() {
>     ActionErrors errors = new ActionErrors();
>     errors = form.validateEdit(mapping, request);
> }
> 
> update() {
>     ActionErrors errors = new ActionErrors();
>     errors = form.validateUpdate(mapping, request);
> }
> 
> Because the rules for validating edit and update are different.  You 
> could define different action-mappings in your struts config for each 
> dispatch method, and then a form in your validation.xml for each 
> action-mapping, where the form name is the same as the path property of 
> the action-mapping, but doesn't this defeat the purpose of the dispatch 
> action?  Why not just have separate actions at that point?  I think the 
> answer is to just not use the dispatch action with the validator, but I 
> wanted to know if others had found a way to do it.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 


-- 
struts 1.1 + tomcat 5.0.16 + java 1.4.2
Linux 2.4.20 Debian


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