You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by specdev2 <fr...@hotmail.com> on 2008/01/29 16:18:16 UTC

How does one get the "validate" method to be called?

Hi,

My action is extending ActionSupport and overriding the "validate" method.
However, the validate method is not being called.

I have set the form tag validate attribute to true, but it makes no
difference.

What am I missing?

Thanks.
-- 
View this message in context: http://www.nabble.com/How-does-one-get-the-%22validate%22-method-to-be-called--tp15160502p15160502.html
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: How does one get the "validate" method to be called?

Posted by Laurie Harper <la...@holoweb.net>.
That would seem to suggest that the validation interceptor relies on 
some work done by one of the interceptors you've removed from your 
stack, no? Try listing all the validators that are in the default stack 
and then commenting out the ones you don't want, one at a time, until 
you identify which one you need to retain.

L.

specdev2 wrote:
> A break point in debug mode.
> Again, I get to the break point if I use the default stack as follow:
> 
> <action name="toHtml" method="toHtml"
> class="com.tchegbe.demo.action.ToHtmlActions">            
>             <interceptor-ref name="defaultStack"/>
>             <result name="input">toHtmlUtilityViewDef</result>
>         </action>
> 
> 
> newton.dave wrote:
>> From: specdev2 <fr...@hotmail.com>
>>> There is just no logical reason as to why my stack would not work.
>>
>> Oh.
>>
>>
>>> Again, here is my stack:
>>
>> What evidence do you have that your validate() method isn't being called?
>>
>>
>> Dave
>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> 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: How does one get the "validate" method to be called?

Posted by Musachy Barroso <mu...@gmail.com>.
"workflow" interceptor used to call "validate" in 2.0.x, on 2.1
"validate" is called by the "validation" interceptor.

musachy

On Jan 29, 2008 12:02 PM, specdev2 <fr...@hotmail.com> wrote:
>
> Just to clarify, the following works as desired:
>
> <action name="toHtml" method="toHtml"
> class="com.tchegbe.demo.action.ToHtmlActions">
>             <interceptor-ref name="servletConfig"/>
>             <interceptor-ref name="fileUpload"/>
>             <interceptor-ref name="params"/>
>             <interceptor-ref name="workflow"/>
>             <result name="input">toHtmlUtilityViewDef</result>
>         </action>
>
> The action validate() method gets called properly by the Workflow
> Interceptor.
> http://struts.apache.org/2.x/docs/workflow-interceptor.html
> --
> View this message in context: http://www.nabble.com/How-does-one-get-the-%22validate%22-method-to-be-called--tp15160502p15163957.html
>
> 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
>
>



-- 
"Hey you! Would you help me to carry the stone?" Pink Floyd

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


Re: How does one get the "validate" method to be called?

Posted by specdev2 <fr...@hotmail.com>.
Just to clarify, the following works as desired:

<action name="toHtml" method="toHtml"
class="com.tchegbe.demo.action.ToHtmlActions">            
            <interceptor-ref name="servletConfig"/>
            <interceptor-ref name="fileUpload"/>
            <interceptor-ref name="params"/>            
            <interceptor-ref name="workflow"/>
            <result name="input">toHtmlUtilityViewDef</result>
        </action>

The action validate() method gets called properly by the Workflow
Interceptor.
http://struts.apache.org/2.x/docs/workflow-interceptor.html
-- 
View this message in context: http://www.nabble.com/How-does-one-get-the-%22validate%22-method-to-be-called--tp15160502p15163957.html
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: How does one get the "validate" method to be called?

Posted by specdev2 <fr...@hotmail.com>.
Ok, I found the issue.

The Workflow Interceptor is the one that calls validate.
Hence, that's the interceptor I needed.

The application now works fine.

Thanks for all the help Dave.
-- 
View this message in context: http://www.nabble.com/How-does-one-get-the-%22validate%22-method-to-be-called--tp15160502p15163616.html
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: How does one get the "validate" method to be called?

Posted by specdev2 <fr...@hotmail.com>.
A break point in debug mode.
Again, I get to the break point if I use the default stack as follow:

<action name="toHtml" method="toHtml"
class="com.tchegbe.demo.action.ToHtmlActions">            
            <interceptor-ref name="defaultStack"/>
            <result name="input">toHtmlUtilityViewDef</result>
        </action>


newton.dave wrote:
> 
> From: specdev2 <fr...@hotmail.com>
>> There is just no logical reason as to why my stack would not work.
> 
> 
> Oh.
> 
> 
>> Again, here is my stack:
> 
> 
> What evidence do you have that your validate() method isn't being called?
> 
> 
> Dave
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/How-does-one-get-the-%22validate%22-method-to-be-called--tp15160502p15163537.html
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: How does one get the "validate" method to be called?

Posted by specdev2 <fr...@hotmail.com>.
Thanks Dave.

In fact, my problem relate to an interceptor stack problem.
If I use the defautStack, it works.
But if I do the following it does not:

<action name="toHtml" method="toHtml"
class="com.tchegbe.demo.action.ToHtmlActions">            
            <interceptor-ref name="servletConfig"/>
            <interceptor-ref name="fileUpload"/>
            <interceptor-ref name="params"/>            
            <interceptor-ref name="validation"/>
            <result>toHtmlUtilityViewDef</result>
        </action>


newton.dave wrote:
> 
> specdev2 <fr...@hotmail.com> wrote:
>> My action is extending ActionSupport and overriding the
>> "validate" method. However, the validate method is not 
>> being called.
> 
> 
> 1. Are you using the default interceptor stack? 
> 2. Have you configured any interceptors for the action in question?
> 
> 
>> I have set the form tag validate attribute to true, but 
>> it makes no difference.
> 
> 
> <s:form...>'s "validate" attribute does not control server-side validation
> (unless you're using the "ajax" theme, I guess).
> 
> 
> Dave
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/How-does-one-get-the-%22validate%22-method-to-be-called--tp15160502p15162591.html
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: How does one get the "validate" method to be called?

Posted by specdev2 <fr...@hotmail.com>.
Right now, I am forced to define a different namespace for each group of
actions with a different default stack.

Unlike the example discussed thus far, my action definitions don't specify
an interceptor.
The code posted is a little unique in that only this action uses the shown
set of interceptors.

So, this is what I do:
package x-name namespace X -> default stack -> actions
package y-name  namespace Y -> different default stack -> actions

I wish I did not have to define a different namespace just to be able to
define different default stacks.
-- 
View this message in context: http://www.nabble.com/How-does-one-get-the-%22validate%22-method-to-be-called--tp15160502p15165239.html
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: How does one get the "validate" method to be called?

Posted by specdev2 <fr...@hotmail.com>.
This is the default stack:

<interceptor-stack name="defaultStack">
                <interceptor-ref name="exception"/>
                <interceptor-ref name="alias"/>
                <interceptor-ref name="servletConfig"/>
                <interceptor-ref name="prepare"/>
                <interceptor-ref name="i18n"/>
                <interceptor-ref name="chain"/>
                <interceptor-ref name="debugging"/>
                <interceptor-ref name="profiling"/>
                <interceptor-ref name="scopedModelDriven"/>
                <interceptor-ref name="modelDriven"/>
                <interceptor-ref name="fileUpload"/>
                <interceptor-ref name="checkbox"/>
                <interceptor-ref name="staticParams"/>
                <interceptor-ref name="params">
                  dojo\..*
                </interceptor-ref>
                <interceptor-ref name="conversionError"/>
                <interceptor-ref name="validation">
                    input,back,cancel,browse
                </interceptor-ref>
                <interceptor-ref name="workflow">
                    input,back,cancel,browse
                </interceptor-ref>
            </interceptor-stack>


There is just no logical reason as to why my stack would not work.

Again, here is my stack:
<action name="toHtml" method="toHtml"
class="com.tchegbe.demo.action.ToHtmlActions">            
            <interceptor-ref name="servletConfig"/>
            <interceptor-ref name="fileUpload"/>
            <interceptor-ref name="params"/>            
            <interceptor-ref name="validation"/>
            <result name="input">toHtmlUtilityViewDef</result>
        </action>

servletConfig, fileUpload, and params are called just fine.
-- 
View this message in context: http://www.nabble.com/How-does-one-get-the-%22validate%22-method-to-be-called--tp15160502p15163199.html
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: How does one get the "validate" method to be called?

Posted by specdev2 <fr...@hotmail.com>.
So, as I was saying, I don't like having to define multiple namespaces just
to be able to define a default stack for a different group of actions.

In the last example, if I give package B a namespace, it will work with each
package having its own default stack.
-- 
View this message in context: http://www.nabble.com/How-does-one-get-the-%22validate%22-method-to-be-called--tp15160502p15169391.html
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: How does one get the "validate" method to be called?

Posted by specdev2 <fr...@hotmail.com>.
When you specify a default stack for a package in which an action is part of,
you do not have to specify an interceptor or interceptor stack on the action
mapping.
This makes maintenance far easier.

In any case, I am referring to being able to do this:

<package name="A" extends="struts-default">
   <interceptors>
        <interceptor-stack name="emptyStack">
           <interceptor-ref name="empty"/>
        </interceptor-stack>
        <interceptor-stack name="aGivenStack">
           <interceptor-ref name="something"/>
           <interceptor-ref name="something2"/>
        </interceptor-stack>
    </interceptors>
    <default-interceptor-ref name="emptyStack"/>

	<action name="action" class="my.package.AClass">
	    <result>aPage.jsp</result>
	</action>
</package>

<package name="B" extends="A">
	<default-interceptor-ref name="aGivenStack"/>
	
	<action name="action" class="my.package.BClass">
	    <result>aPage.jsp</result>
	</action>
</package>

The only thing preventing being able to do that, is that the default stack
defined in package B will override the default stack define in package A
because they have the same namespace.
-- 
View this message in context: http://www.nabble.com/How-does-one-get-the-%22validate%22-method-to-be-called--tp15160502p15169389.html
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: How does one get the "validate" method to be called?

Posted by specdev2 <fr...@hotmail.com>.
I also have this:

<interceptors>
            <interceptor-stack name="emptyStack">
                <interceptor-ref name="empty"/>
            </interceptor-stack>
</interceptors>
        
<default-interceptor-ref name="emptyStack"/>

So:
1. I override the default stack.
2. I specify the exact interceptor(s) I need per action.

This is to avoid useless processing.
There is a fix in the work (a dtd fix) that will enable me to have a truely
empty stack.
Currently, the dtd forces you to define at least one interceptor whereas
there is no requirement to have an interceptor in a given stack.
-- 
View this message in context: http://www.nabble.com/How-does-one-get-the-%22validate%22-method-to-be-called--tp15160502p15163494.html
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: How does one get the "validate" method to be called?

Posted by specdev2 <fr...@hotmail.com>.
Dave,

I have to disagree with you on customizing the interceptors.
It is just sloppy to use a generic stack that calls every interceptor.
Important issues also get lost when you do that.

The true issue with Struts2 is the poor documentation.
Worst is the fact that some of the defaults just aren't smart.

I really wish there was a way to group actions for the purpose of applying
default stacks without being forced to define a namespace or overriding  the
default stack of an existing namespace.


newton.dave wrote:
> 
> From: specdev2 <fr...@hotmail.com>
>> The action validate() method gets called properly by the Workflow
>> Interceptor.
>> http://struts.apache.org/2.x/docs/workflow-interceptor.html
> 
> 
> Oh, you're right [for that version of XWork].
> 
> 
> You'll need to change that when you upgrade S2, though; current XWork does
> not work this way.
> 
> 
> While I can appreciate the desire to "optimize" your interceptor stacks
> you are configuring yourself into a corner and are opening your
> application up to potential issues as the framework evolves.
> 
> 
> IMO it's not worth it.
> 
> 
> Dave
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/How-does-one-get-the-%22validate%22-method-to-be-called--tp15160502p15164612.html
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