commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Rodrigo Canabrava" <canab...@gmail.com>
Subject Re: [Validator] Validator usage with DispatchAction
Date Wed, 02 May 2007 17:28:23 GMT
I think the best approach for what you want is to define an <action> entry
for each method, in the struts-config,
and to define the validations using the action-mapping name.

For example:

I do like this for the action mapping:

        <action path="/*Action*"
            type="org.apache.struts.actions.ForwardAction"
            parameter="/{1}DispatchAction{2}.do?operation={2}" />

        <action path="/*DispatchAction*"
            type="package.{1}Action"
            name="{1}Form" scope="session" input="{1}Page"
            parameter="operation" validate="true">

            <forward name="Page" path="{1}{2}Page" />

        </action>

Then, on the validator.xml definitions:

      <form name="/MyDispatchActionSearch">
             ...
      </form>

      <form name="/MyDispatchActionCreate">
             ...
      </form>

      <form name="/MyDispatchActionUpdate">
             ...
      </form>

With this, when you call, for example "/MyActionCreate.do", it matches the
first mapping, which forwards to "/MyDispatchActionCreate?operation=create".
The second mapping will then associate the call with a "package.MyAction"
class, and a MyForm (that should be declared in a non generic way, in the
form-bean section). The second mapping validates the form according to the
definition with the action name, that is: "/MyDispatchActionCreate".
Observe that, for every method you call (/MyActionCreate, /MyActionUpdate,
etc.), you will have the same form: MyForm.

At last, I use two generic mappings, so I don't have to keep a hidden field
with the operation.

You could also do the validation with just one generic action mapping, or
with non generic mappings as well. The trick is to create one action-mapping
for each method, in this case.

a+
Rodrigo


2007/5/2, Kenneth Ballard <kballard@bcgi.net>:
>
> I was looking at that this link
> (http://struts.apache.org/1.x/struts-extras/dispatchValidator.html)
> about using the "page" attribute when validating forms submitted for a
> Struts DispatchAction so that only certain fields are validated when
> submitting a form for a particular method of the DispatchAction. The
> technique is recommended for use with wizard-like flows so the "page"
> attribute refers to the sequence of the step in the flow. But what about
> the case where you have grouped a set of logically related Actions into
> a single DispatchAction (and they share the same coarse-grained
> ActionForm) but there is no flow? Is it also recommended that you use
> this technique in these sorts of cases? The major difference is that
> there is no set sequence of steps (i.e. a user might only use a method
> or two of the DispatchAction in a given use case) so the "page"
> attribute just functions as a unique identifier of the validation. Is
> this considered proper usage of Validator? Are there any problems with
> this approach?
>
>
>
> Thanks,
>
> Ken
>
>
>
>
>
>
> -----------------------------------------
> The information contained in this e-mail message and any
> attachments is confidential, and is intended only for the use of
> the party to whom it is addressed. This message and any attachments
> herein are subject to scanning and may be monitored at any time for
> review.  If you are not the above-named intended recipient, you are
> hereby notified that any dissemination, copying or disclosure of
> this communication is strictly prohibited. If you have received
> this communication in error, please notify Boston Communications
> Group, Inc. immediately by replying to this message or by
> telephoning (781) 904-5000, and destroy this message and its
> attachments, without making any copy or distribution.

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message