You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by Deepika Malik <de...@patni.com> on 2002/05/17 02:37:37 UTC

RE: Struts Validations ??

hi,
I am myself doing quite a bit of research on this.
but have not been able to come to an effective solution.

According to me the simpler validations should be in javascript.
as this would save
1)one trip to the server.
2)would not make the page too heavy with javascript.
3)too complex validations in javascript are always a pain.
but these validation should again be repeated on the server 'cos
javascript validation can easily be disabled on the browser.

What you need to do in validate method of actionform
for server side validation is:
	public ActionErrors validate(ActionMapping mapping,
                                 HttpServletRequest request)
	 {

        ActionErrors errors = new ActionErrors();
      	 if (formAttribute == null)
        	  errors.add("formAttribute ", new
ActionError("error.username.required"));


        return errors;

    }
lets say you are validating that your formAttribute cannot be null.
then you will add this error to "errors" object with the same name as your
attribute.
In this case,formAttribute.
error.username.required -have this entry in your properties file.
and in your jsp page
<html:errors property="formAttribute"/>
this will display your error.

Thanks,
Deepika

-----Original Message-----
From: Rajendra Yadav [mailto:ry771@yahoo.com]
Sent: Friday, November 29, 2002 3:17 AM
To: struts-dev@jakarta.apache.org
Cc: struts-users@jakarta.apache.org
Subject: Struts Validations ??



Hi All,

I need some information regarding the usgae of the struts validations.

If anyone is using it, please let me know the pros and cons of it and how
effective it is if compared to javascript validations.

Thanks,

- Raj



---------------------------------
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>