You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by laredotornado <la...@gmail.com> on 2009/02/27 18:41:13 UTC

Struts 2 question about validation and forwarding

Hi,

If request validation fails, how can I forward the user to a different page
than that from which they came?  The scenario is that an external web site
is going to invoke our site with something like
"/ourForm.do?param1=xxx&param2=yyyy" and if their parameters are not valid,
we want to forward them to another page on our site.

Thanks for your help, - Dave

-- 
View this message in context: http://www.nabble.com/Struts-2-question-about-validation-and-forwarding-tp22250708p22250708.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: Struts 2 question about validation and forwarding

Posted by Dave Newton <ne...@yahoo.com>.
laredotornado wrote:
> But it seems like the "ActionErrors validate" method from my ActionForm class
> is called, fails, and my execute handler is not called.  Is there a way in
> the struts-config.xml file that I can set up a foward upon validation
> failure?
> 
> This is what my struts action is currently ...
> 
>         <action path="/hhFlow"
>                   type="com.myco.regui.struts.accounts.AccountsAction"
>                   scope="request"
>                   name="REAccountLookUpBean"
>                   validate="true">
>         </action>     

That's Struts 1, not Struts 2.

You may need to call validation manually (not a big deal) and return a 
different ActionForward on failure.

FWIW, that's what I almost *always* did in S1: I had a base action class 
that went to input on a GET, validated on a POST, and could be set up to 
do various things on validation failure. YMMV.

Dave


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


Re: Struts generate code

Posted by Angelo zerr <an...@gmail.com>.
Hi,

If you use Eclipse, you can see Akrogen <http://akrogen.sourceforge.net/>which
is Eclipse plugin to describe your wizard with XML (XUL) and Javascript and
link it to a template (XSL, Freemarker, Velocity...)

Akrogen works wit catalog (folder which contains, XUL wiizard, templates..).
You can find catalog for Struts1.x at
http://akrogen.sourceforge.net/struts-catalog/struts1x.html
But it's easy to write your own catalog to generate what you want.

Regards Angelo

2009/2/27 Musachy Barroso <mu...@gmail.com>

> You can use Java APT:
> http://java.sun.com/j2se/1.5.0/docs/guide/apt/GettingStarted.html
>
> We use it for struts-annotations (internal tool to generate TLD files for
> tags):
>
> http://svn.apache.org/viewvc/struts/maven/trunk/struts-annotations/
>
> musachy
>
> On Fri, Feb 27, 2009 at 12:59 PM, Mileidys Gonzalez Prieto
> <mi...@i-frontier.net> wrote:
> > Hi, Im searching for tools that allows to generate some struts resources,
> > like validation and app resources. I was looking around and I found the
> > xDoclet annotations for to generate struts code, but my database is
> really
> > so big, not so easy going to all the POJOs for to do that. Any other way,
> > please?
> > I was trying also to find ways to generate the POJOs with xDoclet
> > annotations because anyway hibernate contains max-lenght and no-null
> > values...
> >
> > Thank you,
> >
> > Mileidys Gonzalez Prieto
> >
> >
> > ---------------------------------------------------------------------
> > 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: Struts generate code

Posted by Musachy Barroso <mu...@gmail.com>.
You can use Java APT:
http://java.sun.com/j2se/1.5.0/docs/guide/apt/GettingStarted.html

We use it for struts-annotations (internal tool to generate TLD files for tags):

http://svn.apache.org/viewvc/struts/maven/trunk/struts-annotations/

musachy

On Fri, Feb 27, 2009 at 12:59 PM, Mileidys Gonzalez Prieto
<mi...@i-frontier.net> wrote:
> Hi, Im searching for tools that allows to generate some struts resources,
> like validation and app resources. I was looking around and I found the
> xDoclet annotations for to generate struts code, but my database is really
> so big, not so easy going to all the POJOs for to do that. Any other way,
> please?
> I was trying also to find ways to generate the POJOs with xDoclet
> annotations because anyway hibernate contains max-lenght and no-null
> values...
>
> Thank you,
>
> Mileidys Gonzalez Prieto
>
>
> ---------------------------------------------------------------------
> 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


Struts generate code

Posted by Mileidys Gonzalez Prieto <mi...@i-frontier.net>.
Hi, Im searching for tools that allows to generate some struts resources,
like validation and app resources. I was looking around and I found the
xDoclet annotations for to generate struts code, but my database is really
so big, not so easy going to all the POJOs for to do that. Any other way,
please?
I was trying also to find ways to generate the POJOs with xDoclet
annotations because anyway hibernate contains max-lenght and no-null
values...

Thank you,

Mileidys Gonzalez Prieto


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


Re: Struts 2 question about validation and forwarding

Posted by Dave Newton <ne...@yahoo.com>.
laredotornado wrote:
> I only want to forward if validation fails -- i.e. don't need to run the
> "execute" method.  But I don't know how to set that up in my
> struts-config.xml file (or some other file if that's what's needed).  How do
> I do that?

IIRC execute isn't executed on a validation failure; that's what the 
"input" attribute is for, so S1 knows what to do via config w/o 
programmer intervention.

If you're working outside of the framework defaults then you'll probably 
need to do something manually, although if this is an application-wide 
requirement something could probably be done with a custom request 
processor.

Dave


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


Re: Struts 2 question about validation and forwarding

Posted by laredotornado <la...@gmail.com>.
Hi,

I only want to forward if validation fails -- i.e. don't need to run the
"execute" method.  But I don't know how to set that up in my
struts-config.xml file (or some other file if that's what's needed).  How do
I do that?

Or is the only way to do this is as David Newton suggested -- moving
validation into my execute method and forwarding appropriately.

Thanks, - Dave



Burton Rhodes wrote:
> 
> Exactly. If validation fails, execute will not be called by design.
> Since all you want to do is forward, you shouldn't need to run your
> execute method. The forwarding will take place in your struts.xml file
> as previously suggested.
> 
> If you need to execute code regardless of the validation, look into
> the prepare method.
> 
> On 2/27/09, laredotornado <la...@gmail.com> wrote:
>>
>> But it seems like the "ActionErrors validate" method from my ActionForm
>> class
>> is called, fails, and my execute handler is not called.  Is there a way
>> in
>> the struts-config.xml file that I can set up a foward upon validation
>> failure?
>>
>> This is what my struts action is currently ...
>>
>>         <action path="/hhFlow"
>>                   type="com.myco.regui.struts.accounts.AccountsAction"
>>                   scope="request"
>>                   name="REAccountLookUpBean"
>>                   validate="true">
>>         </action>
>>
>>  - Dave
>>
>>
>> Jim Kiley wrote:
>>>
>>> Just have the result of the input() method return them to a different
>>> page
>>> under that condition.
>>>
>>> On Fri, Feb 27, 2009 at 12:41 PM, laredotornado
>>> <la...@gmail.com>wrote:
>>>
>>>>
>>>> Hi,
>>>>
>>>> If request validation fails, how can I forward the user to a different
>>>> page
>>>> than that from which they came?  The scenario is that an external web
>>>> site
>>>> is going to invoke our site with something like
>>>> "/ourForm.do?param1=xxx&param2=yyyy" and if their parameters are not
>>>> valid,
>>>> we want to forward them to another page on our site.
>>>>
>>>> Thanks for your help, - Dave
>>>>
>>>> --
>>>> View this message in context:
>>>> http://www.nabble.com/Struts-2-question-about-validation-and-forwarding-tp22250708p22250708.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
>>>>
>>>>
>>>
>>>
>>> --
>>> Jim Kiley
>>> Technical Consultant | Summa
>>> [p] 412.258.3346 [m] 412.445.1729
>>> http://www.summa-tech.com
>>>
>>>
>>
>> --
>> View this message in context:
>> http://www.nabble.com/Struts-2-question-about-validation-and-forwarding-tp22250708p22250852.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
>>
>>
> 
> -- 
> Sent from my mobile device
> 
> ---------------------------------------------------------------------
> 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/Struts-2-question-about-validation-and-forwarding-tp22250708p22289465.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: Struts 2 question about validation and forwarding

Posted by Burton Rhodes <bu...@gmail.com>.
Exactly. If validation fails, execute will not be called by design.
Since all you want to do is forward, you shouldn't need to run your
execute method. The forwarding will take place in your struts.xml file
as previously suggested.

If you need to execute code regardless of the validation, look into
the prepare method.

On 2/27/09, laredotornado <la...@gmail.com> wrote:
>
> But it seems like the "ActionErrors validate" method from my ActionForm
> class
> is called, fails, and my execute handler is not called.  Is there a way in
> the struts-config.xml file that I can set up a foward upon validation
> failure?
>
> This is what my struts action is currently ...
>
>         <action path="/hhFlow"
>                   type="com.myco.regui.struts.accounts.AccountsAction"
>                   scope="request"
>                   name="REAccountLookUpBean"
>                   validate="true">
>         </action>
>
>  - Dave
>
>
> Jim Kiley wrote:
>>
>> Just have the result of the input() method return them to a different page
>> under that condition.
>>
>> On Fri, Feb 27, 2009 at 12:41 PM, laredotornado
>> <la...@gmail.com>wrote:
>>
>>>
>>> Hi,
>>>
>>> If request validation fails, how can I forward the user to a different
>>> page
>>> than that from which they came?  The scenario is that an external web
>>> site
>>> is going to invoke our site with something like
>>> "/ourForm.do?param1=xxx&param2=yyyy" and if their parameters are not
>>> valid,
>>> we want to forward them to another page on our site.
>>>
>>> Thanks for your help, - Dave
>>>
>>> --
>>> View this message in context:
>>> http://www.nabble.com/Struts-2-question-about-validation-and-forwarding-tp22250708p22250708.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
>>>
>>>
>>
>>
>> --
>> Jim Kiley
>> Technical Consultant | Summa
>> [p] 412.258.3346 [m] 412.445.1729
>> http://www.summa-tech.com
>>
>>
>
> --
> View this message in context:
> http://www.nabble.com/Struts-2-question-about-validation-and-forwarding-tp22250708p22250852.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
>
>

-- 
Sent from my mobile device

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


Re: Struts 2 question about validation and forwarding

Posted by laredotornado <la...@gmail.com>.
But it seems like the "ActionErrors validate" method from my ActionForm class
is called, fails, and my execute handler is not called.  Is there a way in
the struts-config.xml file that I can set up a foward upon validation
failure?

This is what my struts action is currently ...

        <action path="/hhFlow"
                  type="com.myco.regui.struts.accounts.AccountsAction"
                  scope="request"
                  name="REAccountLookUpBean"
                  validate="true">
        </action>         

 - Dave


Jim Kiley wrote:
> 
> Just have the result of the input() method return them to a different page
> under that condition.
> 
> On Fri, Feb 27, 2009 at 12:41 PM, laredotornado
> <la...@gmail.com>wrote:
> 
>>
>> Hi,
>>
>> If request validation fails, how can I forward the user to a different
>> page
>> than that from which they came?  The scenario is that an external web
>> site
>> is going to invoke our site with something like
>> "/ourForm.do?param1=xxx&param2=yyyy" and if their parameters are not
>> valid,
>> we want to forward them to another page on our site.
>>
>> Thanks for your help, - Dave
>>
>> --
>> View this message in context:
>> http://www.nabble.com/Struts-2-question-about-validation-and-forwarding-tp22250708p22250708.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
>>
>>
> 
> 
> -- 
> Jim Kiley
> Technical Consultant | Summa
> [p] 412.258.3346 [m] 412.445.1729
> http://www.summa-tech.com
> 
> 

-- 
View this message in context: http://www.nabble.com/Struts-2-question-about-validation-and-forwarding-tp22250708p22250852.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: Struts 2 question about validation and forwarding

Posted by Jim Kiley <jh...@summa-tech.com>.
Just have the result of the input() method return them to a different page
under that condition.

On Fri, Feb 27, 2009 at 12:41 PM, laredotornado <la...@gmail.com>wrote:

>
> Hi,
>
> If request validation fails, how can I forward the user to a different page
> than that from which they came?  The scenario is that an external web site
> is going to invoke our site with something like
> "/ourForm.do?param1=xxx&param2=yyyy" and if their parameters are not valid,
> we want to forward them to another page on our site.
>
> Thanks for your help, - Dave
>
> --
> View this message in context:
> http://www.nabble.com/Struts-2-question-about-validation-and-forwarding-tp22250708p22250708.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
>
>


-- 
Jim Kiley
Technical Consultant | Summa
[p] 412.258.3346 [m] 412.445.1729
http://www.summa-tech.com