On Thu, Jun 11, 2009 at 8:23 AM, Jim Collings<jlistn...@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-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org

Reply via email to