You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Franz Wong <fr...@gmail.com> on 2010/08/11 15:51:33 UTC

How do we repopulate controls when validation fails?

Hi,

I have read the documentation "How do we repopulate controls when validation
fails" [1]. I tried the action tag solution. However, when there is a
validation error, the execute method of the action in <s:action> is not
called.

I don't choose the Preparable solution because the parameter required is not
ready in the Prepare stage. (For the first time of visit, the parameter is
set to default.) And I don't want to call the preparation twice in both
execute and prepare. So what is the best way to repopulate controls for
normal case and revisit after validation error? Should I abandon to validate
the input in validate method?

Thanks.
Franz

[1]
http://struts.apache.org/2.x/docs/how-do-we-repopulate-controls-when-validation-fails.html

Re: How do we repopulate controls when validation fails?

Posted by Franz Wong <fr...@gmail.com>.
Thanks. It solves my problem :)

Franz

On Wed, Aug 11, 2010 at 10:11 PM, Alex Rodriguez Lopez <
alopez@flordeutopia.pt> wrote:

> Don't know if this solves your problem, but maybe it helps to use the
> params-prepare-params trick, calling params interceptor twice, so you have
> your params ready before prepare().
>
> You have an already configured stack, the paramsPrepareParamsStack
>
> From struts-default.xml:
>
> <!-- An example of the paramsPrepareParams trick. This stack
>                 is exactly the same as the defaultStack, except that it
>                 includes one extra interceptor before the prepare
> interceptor:
>                 the params interceptor.
>
>                 This is useful for when you wish to apply parameters
> directly
>                 to an object that you wish to load externally (such as a
> DAO
>                 or database or service layer), but can't load that object
>                 until at least the ID parameter has been loaded. By loading
>                 the parameters twice, you can retrieve the object in the
>                 prepare() method, allowing the second params interceptor to
>                 apply the values on the object. -->
>            <interceptor-stack name="paramsPrepareParamsStack">
>                <interceptor-ref name="exception"/>
>                <interceptor-ref name="alias"/>
>                <interceptor-ref name="i18n"/>
>                <interceptor-ref name="checkbox"/>
>                <interceptor-ref name="multiselect"/>
>                <interceptor-ref name="params">
>                    <param name="excludeParams">dojo\..*,^struts\..*</param>
>                </interceptor-ref>
>                <interceptor-ref name="servletConfig"/>
>                <interceptor-ref name="prepare"/>
>                <interceptor-ref name="chain"/>
>                <interceptor-ref name="modelDriven"/>
>                <interceptor-ref name="fileUpload"/>
>                <interceptor-ref name="staticParams"/>
>                <interceptor-ref name="actionMappingParams"/>
>                <interceptor-ref name="params">
>                    <param name="excludeParams">dojo\..*,^struts\..*</param>
>                </interceptor-ref>
>                <interceptor-ref name="conversionError"/>
>                <interceptor-ref name="validation">
>                    <param
> name="excludeMethods">input,back,cancel,browse</param>
>                </interceptor-ref>
>                <interceptor-ref name="workflow">
>                    <param
> name="excludeMethods">input,back,cancel,browse</param>
>                </interceptor-ref>
>            </interceptor-stack>
>
>
>
>  Hi,
>>
>> I have read the documentation "How do we repopulate controls when
>> validation
>> fails" [1]. I tried the action tag solution. However, when there is a
>> validation error, the execute method of the action in<s:action>  is not
>> called.
>>
>> I don't choose the Preparable solution because the parameter required is
>> not
>> ready in the Prepare stage. (For the first time of visit, the parameter is
>> set to default.) And I don't want to call the preparation twice in both
>> execute and prepare. So what is the best way to repopulate controls for
>> normal case and revisit after validation error? Should I abandon to
>> validate
>> the input in validate method?
>>
>> Thanks.
>> Franz
>>
>> [1]
>>
>> http://struts.apache.org/2.x/docs/how-do-we-repopulate-controls-when-validation-fails.html
>>
>>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: How do we repopulate controls when validation fails?

Posted by Alex Rodriguez Lopez <al...@flordeutopia.pt>.
Don't know if this solves your problem, but maybe it helps to use the 
params-prepare-params trick, calling params interceptor twice, so you 
have your params ready before prepare().

You have an already configured stack, the paramsPrepareParamsStack

 From struts-default.xml:

<!-- An example of the paramsPrepareParams trick. This stack
                  is exactly the same as the defaultStack, except that it
                  includes one extra interceptor before the prepare 
interceptor:
                  the params interceptor.

                  This is useful for when you wish to apply parameters 
directly
                  to an object that you wish to load externally (such as 
a DAO
                  or database or service layer), but can't load that object
                  until at least the ID parameter has been loaded. By 
loading
                  the parameters twice, you can retrieve the object in the
                  prepare() method, allowing the second params 
interceptor to
                  apply the values on the object. -->
             <interceptor-stack name="paramsPrepareParamsStack">
                 <interceptor-ref name="exception"/>
                 <interceptor-ref name="alias"/>
                 <interceptor-ref name="i18n"/>
                 <interceptor-ref name="checkbox"/>
                 <interceptor-ref name="multiselect"/>
                 <interceptor-ref name="params">
                     <param 
name="excludeParams">dojo\..*,^struts\..*</param>
                 </interceptor-ref>
                 <interceptor-ref name="servletConfig"/>
                 <interceptor-ref name="prepare"/>
                 <interceptor-ref name="chain"/>
                 <interceptor-ref name="modelDriven"/>
                 <interceptor-ref name="fileUpload"/>
                 <interceptor-ref name="staticParams"/>
                 <interceptor-ref name="actionMappingParams"/>
                 <interceptor-ref name="params">
                     <param 
name="excludeParams">dojo\..*,^struts\..*</param>
                 </interceptor-ref>
                 <interceptor-ref name="conversionError"/>
                 <interceptor-ref name="validation">
                     <param 
name="excludeMethods">input,back,cancel,browse</param>
                 </interceptor-ref>
                 <interceptor-ref name="workflow">
                     <param 
name="excludeMethods">input,back,cancel,browse</param>
                 </interceptor-ref>
             </interceptor-stack>


> Hi,
>
> I have read the documentation "How do we repopulate controls when validation
> fails" [1]. I tried the action tag solution. However, when there is a
> validation error, the execute method of the action in<s:action>  is not
> called.
>
> I don't choose the Preparable solution because the parameter required is not
> ready in the Prepare stage. (For the first time of visit, the parameter is
> set to default.) And I don't want to call the preparation twice in both
> execute and prepare. So what is the best way to repopulate controls for
> normal case and revisit after validation error? Should I abandon to validate
> the input in validate method?
>
> Thanks.
> Franz
>
> [1]
> http://struts.apache.org/2.x/docs/how-do-we-repopulate-controls-when-validation-fails.html
>

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