You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by hernan gonzalez <hg...@gmail.com> on 2008/05/22 19:32:56 UTC

s2: Simple 'show empty form' flow

In any webapp the most typical and simple form flow involves two steps:
(from the serverside point of view)

1) show an empty form for the user to fill the fields
2) receive the data, validate ; if ok, process it and show response page;
if not, show the same previous form with error messages

In Struts2, the standard mapping could be (taken from "Struts2 in action")

<action name="Registration" >
  <result>/Registration.jsp</result>
</action>
<action name="Register" class="manning.Register">
  <result>/RegistrationSuccess.jsp</result>
  <result name="input">/Registration.jsp</result>
</action>

Now, this does not seem very nice to me.
-Two mappings for such a simple case seems a little too much
-Duplication/coupling of the input jsp (Registration.jsp) in the two mappings
-Registration.jsp must specify the Register action name in its form tag

This might be simplified by using a single mapping (the second one), by
giving the action a little more intelligence: "has the user submitted anything?
if not, this is just a request to show the input form; then, return
INPUT; elsewhere,
do as usual".
This can be done (the decision "show the empty form" might involve
asking if there
were any parameters, etc), but where ? I want to make that decision
even before the
validation takes places, so that the empty form does not show some
"field X is required",
hence I guess it would be some interceptor's work.
But before trying to write it, I wanted to asked here if this scenario
has not been
considered, as it seems so common...

-- 
Hernán J. González
http://hjg.com.ar/

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