You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by John Hunt <te...@yahoo.com> on 2001/01/10 20:27:39 UTC

struts:errors

Hi 
Say, if I have two forms form1 and form2 in a page and
correspondingly I have two ActionForm classes A1 and
A2 which validate those two forms, how can I display
the errors during validation of form1 and form2
SEPARATELY.
What does <struts:errors/> display in such scenario? 
How can I uniquely identify errors returned by form1
and form2 instead of displaying them together.

Problem 2:
Suppose I have a scenario where I have form1 and form2
( say login and sign up ) in a page. As part of the
validation, I would be having null check for username
& password fields in the each form and return an error
if both fields are null in a form. We would expect the
user to fill either login form or singup form. In such
scenario either path he follows is a success. But
because of our validation checks ( both login and
passwd r null for any one of them he doesnt fill ) we
will be getting an error. Any thoughts as to how we
can handle this?
Thanks
Hunt

__________________________________________________
Do You Yahoo!?
Yahoo! Photos - Share your holiday photos online!
http://photos.yahoo.com/

Re: struts:errors

Posted by Ted Husted <ne...@husted.com>.
The ActionForm in Struts represents a "logical" form in your
application. So, there is not necessary a direct 1:1 relationship
between an ActionForm and a single HTML form on a single page.
Sometimes, the properties of an ActionForm will be presented over
several requests, as in a wizard-type request. Other times, the
properties of a single ActionForm may be presented in several HTML
forms during the same request. 

Given the lockstep request/reply nature of HTTP, I don't see how it is
possible to validate two ActionForms at once. The solution would be to
have a single ActionForm that wraps the properties of Classes "A1" and
"A2", just as your HTML page provides the HTML both form1 and form2 to
the user. Classes A1 and A2 might be represented on several ActionForms
in the course of your application.

A good way to go about this is to setup classes A1 and A2 as data
JavaBeans, and make the databeans instance variables on your dataforms.
Until recently, you would have then had to write mutator and accessor
wrappers for your databean properites, so that the HTML form tag could
see them. 

However ... (dramatic pause) ... using the most recent build, you can
now  use simple/nested/indexed expressions like this:
  
      <html:text property="mailingAddress.street"/>
  
and the appropriate processing will be applied to get the street
address (for initial display) and set the street address (when the form
is processed).

Your validation method would then queue up whatever error messages
should be communicated to the user, and display them all on your input
form. (ActionErrors is a collection.)

In Problem 2, you also have access to the HTTP request in the
validation method, so you could perform a different validation
depending on what HTML page (login or signin) submitted the request. 

Note that you can also defer some (or even all!) validation until the
Action. For example, whether the password as valid for that given
username would probably be verified in the Action, rather than on the
Form, and the user forwarded back to the input form if it didn't check
out. The ActionForm validations are usually about the format of the
input, and could just as well be performed client-side with JavaScript.
(Generating client-side JavaScript validations via custom tags is on
the list for Struts 1.1)

********** REPLY SEPARATOR  ***********

On 1/10/2001 at 11:27 AM John Hunt wrote:

Hi 
Say, if I have two forms form1 and form2 in a page and
correspondingly I have two ActionForm classes A1 and
A2 which validate those two forms, how can I display
the errors during validation of form1 and form2
SEPARATELY.
What does <struts:errors/> display in such scenario? 
How can I uniquely identify errors returned by form1
and form2 instead of displaying them together.

Problem 2:
Suppose I have a scenario where I have form1 and form2
( say login and sign up ) in a page. As part of the
validation, I would be having null check for username
& password fields in the each form and return an error
if both fields are null in a form. We would expect the
user to fill either login form or singup form. In such
scenario either path he follows is a success. But
because of our validation checks ( both login and
passwd r null for any one of them he doesnt fill ) we
will be getting an error. Any thoughts as to how we
can handle this?
Thanks
Hunt

__________________________________________________
Do You Yahoo!?
Yahoo! Photos - Share your holiday photos online!
http://photos.yahoo.com/