You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Jim Collings <jl...@gmail.com> on 2009/06/11 14:23:37 UTC
Whats the best way to do validation messages on the same page?
There's got to be a better way of doing this than the way that I am doing it.
Convention plugin.
According to my projects requirements error/validation/success
messages are supposed to show on the jsp that generated them. So if I
am on a page that adds a record and I leave all the fields blank,
selecting submit will display some errors on that page but will not
move on to a different page.
All of these pages are in the /content dir so if I have:
some-file.jsp and SomeFileAction.java and if SomeFileAction extends
ActionSupport implements Preparable, then execute() is going to get
called when ever the page is loaded even though it's empty and just
returns "success"... I have to override and annotate execute with
@SkipValidation to prevent messages from being displayed when the user
has first loaded the page. The form on the some-file.jsp calls
some-file!doSomething when the Submit button is selected. This turns
things into a real mess. What the convention plugin does is consistent
but not always predictable. I basically had to break with the
conventions and use a few @Results and an additional action to get
some predictability out of it.
Anyway... how would you have done this?
Jim C.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Whats the best way to do validation messages on the same page?
Posted by Wes Wannemacher <we...@wantii.com>.
On Thu, Jun 11, 2009 at 8:23 AM, Jim Collings<jl...@gmail.com> wrote:
> There's got to be a better way of doing this than the way that I am doing it.
>
> Convention plugin.
>
> According to my projects requirements error/validation/success
> messages are supposed to show on the jsp that generated them. So if I
> am on a page that adds a record and I leave all the fields blank,
> selecting submit will display some errors on that page but will not
> move on to a different page.
> All of these pages are in the /content dir so if I have:
>
> some-file.jsp and SomeFileAction.java and if SomeFileAction extends
> ActionSupport implements Preparable, then execute() is going to get
> called when ever the page is loaded even though it's empty and just
> returns "success"... I have to override and annotate execute with
> @SkipValidation to prevent messages from being displayed when the user
> has first loaded the page. The form on the some-file.jsp calls
> some-file!doSomething when the Submit button is selected. This turns
> things into a real mess. What the convention plugin does is consistent
> but not always predictable. I basically had to break with the
> conventions and use a few @Results and an additional action to get
> some predictability out of it.
>
> Anyway... how would you have done this?
Generally, I leave execute to actually do the work... I mean, rather
than present a form on the page returned by the "success" result, I
will make the first stop to a page be the "input" result. If you link
your users to the "input" result, then, even though the form fields
are empty, struts will skip validation (by default). It is from this
page that I will submit to the execute method of the action. It's hard
to draw a flowchart in an email, but typical process flow is like this
-
landing page -> process form
"input" result "execute" method
At this point, if validation fails, the framework will send the user
to the "input" result with validation errors, or continue to the
"success" result.
I think most of the CRUD tutorials and examples in the docs follow a
similar flow.
It is not that it is a requirement to do it this way. But, I'm pretty
sure this is the "convention" that the conventions plugin is meant to
provide. Of course, you can break out of it by configuring things
(using the @Result(s) annotation, changing interceptor configuration
for how validation is run, and using the @SkipValidation annotation).
-Wes
--
Wes Wannemacher
Author - Struts 2 In Practice
Includes coverage of Struts 2.1, Spring, JPA, JQuery, Sitemesh and more
http://www.manning.com/wannemacher
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Whats the best way to do validation messages on the same page?
Posted by st...@gmail.com.
I would skeptical about excluding execute. As Wes points out, the framework
is designed to bypass validating input initially. After all, it's kind of
difficult validating a form you have not yet had the chance to ill out!
On Thu, Jun 11, 2009 at 8:53 AM, Kishan G. Chellap Paandy <
kishanchellapaandy_g@spanservices.com> wrote:
> Hi Jim,
>
> You can exclude methods (in your case execute method) from validation using
> workflow interceptor exclude methods parameter.
>
> <interceptor-ref name="workflow">
> <param name="excludeMethods">execute</param>
> </interceptor-ref>
>
> May be this could help.
>
> Thank you.
> Regards,
> Kishan.G
>
> Team Leader.
> www.spansystems.com
>
>
>
> -----Original Message-----
> From: Jim Collings [mailto:jlistnews@gmail.com]
> Sent: Thursday, June 11, 2009 5:54 PM
> To: Struts Users Mailing List
> Subject: Whats the best way to do validation messages on the same page?
>
> There's got to be a better way of doing this than the way that I am doing
> it.
>
> Convention plugin.
>
> According to my projects requirements error/validation/success
> messages are supposed to show on the jsp that generated them. So if I
> am on a page that adds a record and I leave all the fields blank,
> selecting submit will display some errors on that page but will not
> move on to a different page.
> All of these pages are in the /content dir so if I have:
>
> some-file.jsp and SomeFileAction.java and if SomeFileAction extends
> ActionSupport implements Preparable, then execute() is going to get
> called when ever the page is loaded even though it's empty and just
> returns "success"... I have to override and annotate execute with
> @SkipValidation to prevent messages from being displayed when the user
> has first loaded the page. The form on the some-file.jsp calls
> some-file!doSomething when the Submit button is selected. This turns
> things into a real mess. What the convention plugin does is consistent
> but not always predictable. I basically had to break with the
> conventions and use a few @Results and an additional action to get
> some predictability out of it.
>
> Anyway... how would you have done this?
>
>
> Jim C.
>
> ---------------------------------------------------------------------
> 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: Whats the best way to do validation messages on the same page?
Posted by "Kishan G. Chellap Paandy" <ki...@spanservices.com>.
Hi Jim,
You can exclude methods (in your case execute method) from validation using workflow interceptor exclude methods parameter.
<interceptor-ref name="workflow">
<param name="excludeMethods">execute</param>
</interceptor-ref>
May be this could help.
Thank you.
Regards,
Kishan.G
Team Leader.
www.spansystems.com
-----Original Message-----
From: Jim Collings [mailto:jlistnews@gmail.com]
Sent: Thursday, June 11, 2009 5:54 PM
To: Struts Users Mailing List
Subject: Whats the best way to do validation messages on the same page?
There's got to be a better way of doing this than the way that I am doing it.
Convention plugin.
According to my projects requirements error/validation/success
messages are supposed to show on the jsp that generated them. So if I
am on a page that adds a record and I leave all the fields blank,
selecting submit will display some errors on that page but will not
move on to a different page.
All of these pages are in the /content dir so if I have:
some-file.jsp and SomeFileAction.java and if SomeFileAction extends
ActionSupport implements Preparable, then execute() is going to get
called when ever the page is loaded even though it's empty and just
returns "success"... I have to override and annotate execute with
@SkipValidation to prevent messages from being displayed when the user
has first loaded the page. The form on the some-file.jsp calls
some-file!doSomething when the Submit button is selected. This turns
things into a real mess. What the convention plugin does is consistent
but not always predictable. I basically had to break with the
conventions and use a few @Results and an additional action to get
some predictability out of it.
Anyway... how would you have done this?
Jim C.
---------------------------------------------------------------------
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