You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Dan Allen <da...@mojavelinux.com> on 2003/04/07 06:46:25 UTC

an idea for DynaValidatorForm

I just want to bounce this off the list, see if anyone thinks it is
a good idea.  When working the business logic on a multipage form,
you often want to take the user back to the exact page in which the
business logic error occurs (duplicate username, improper upload) so
that the user can fix the problem.  In order to do this, the
following method would be needed in the DynaValidatorForm class:

getPageForField(mapping, fieldName)

Say for instance, I had a multipage form and the user types in a
duplicate username.  Sure, one could assume that the username field
is on the first page, but maybe it is not a username field or it is
not on the first page.  It would be nice in the business logic to do
something like:

 String username = (String) myForm.get("username");
 boolean isDuplicate = checkDuplicateUsername(username);
 if (isDuplicate)
 {
     return mapping.findForward("input" + myForm.getPageForField(mapping, "username"));
 }

That is just pseudocode and not really polished, but it gets across
the point.  Now, the jsp developer could move the username to a
different page and not affect the Action class at all.

Building on this, in my code I would then use a Token (maybe the
same as the struts token, maybe a new one) to mark the form as
completed.  This way, when the user submits one of the pages in the
wizard, I could check to see if the user had already been through to
the end (meaning that the user was revisiting a page to fix errors).
If the form was already completed, I would jump to the business
validation again (skipping any intermediary pages).  This way, if
the user was taken back to page 1, fixed the info, the user would
jump to the end of the wizard when pressing submit where the data is
business validated and processed to persistent store.

However, you can see that being able to determine the page in which
one of the fields occurs is crucial to abstracting this idea
properly.

Maybe I am just obsessed with the multipage form wizard this week,
but I feel as though these ideas might help out some people.

Dan

-- 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
Daniel Allen, <da...@mojavelinux.com>
http://www.mojavelinux.com/
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
It is not enough to succeed.  Others must fail.  
 -- Gore Vidal
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

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