You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by sriram <sr...@nunet-tech.com> on 2003/07/10 08:34:52 UTC

RE: What should be in validate() method when using struts validat or package

Can you please explain how to use validator for client side validations? Any sample code on the web (links would be helpful).
 
 
Thanks
Sriram

-----Original Message-----
From: Nagendra Kumar O V S [mailto:nagendra@ikigo.com] 
Sent: Thursday, July 10, 2003 11:59 AM
To: struts-user@jakarta.apache.org
Subject: Re: What should be in validate() method when using struts validator package



hi,
struts validator provides both client side as well as server side validations.
if u want to use the serverside validations , u have to extend the validatorForm instead of ActionForm and remove the validate() method all together.
but, in my application, i am using validator for client side validations and on the server side i still use plain vanilla Action forms and validation method (for validations) for my own business requirements.
so its a matter of choice.
 
--nagi
 
-------Original Message-------
 
From: Struts Users Mailing  <ma...@jakarta.apache.org> List
Date: Thursday, July 10, 2003 11:42:11 AM
To: 'Struts Users Mailing  <ma...@jakarta.apache.org> List'
Subject: What should be in validate() method when using struts validator package
 
What should be in validate() method when we use Struts Validator package?
Should it be an empty method?

My current validate() method (without using Struts Validator) is as follows:(What should it be if I implement validations in validator-rules.xml and validations.xml)? Pl. suggest.

public ActionErrors validate(ActionMapping mapping,
javax.servlet.http.HttpServletRequest request) {
// maintenance forms do new, update and delete, but also searches and create new for
// fkey resolvers. Only new and update actually need validation.
if (!lrAction_.equals("New") && !lrAction_.equals("Update")) return null;

ActionErrors errs = new ActionErrors();
SupportValues support = new SupportValues();



try {
support.setContactName(contactName_);
} catch (IllegalArgumentException ex) {
errs.add(FLD_CONTACT_NAME,new ActionError("supportviewform.error_contact_name",ex.getMessage()));
}
try {
support.setContactDetail(contactDetail_);
} catch (IllegalArgumentException ex) {
errs.add(FLD_CONTACT_DETAIL,new ActionError("supportviewform.error_contact_detail",ex.getMessage()));
}
try {
support.setPhoneNo(phoneNo_);
} catch (IllegalArgumentException ex) {
errs.add(FLD_PHONE_NO,new ActionError("supportviewform.error_phone_no",ex.getMessage()));
}
try {
support.setEmailAddr(emailAddr_);
} catch (IllegalArgumentException ex) {
errs.add(FLD_EMAIL_ADDR,new ActionError("supportviewform.error_email_addr",ex.getMessage()));
}
try {
support.setSubject(subject_);
} catch (IllegalArgumentException ex) {
errs.add(FLD_SUBJECT,new ActionError("supportviewform.error_subject",ex.getMessage()));
}
try {
support.setMessage(message_);
} catch (IllegalArgumentException ex) {
errs.add(FLD_MESSAGE,new ActionError("supportviewform.error_message",ex.getMessage()));
} 
if (errs.empty()) return null;

// preserve selected values in the form, so on error don't lose them all.
preserveSelectedValues(request);

return errs;
} // end of validate



			
____________________________________________________
 <http://www.incredimail.com/redir.asp?ad_id=309&lang=9>   IncrediMail - Email has finally evolved -  <http://www.incredimail.com/redir.asp?ad_id=309&lang=9> Click Here 


RE: What should be in validate() method when using struts validator package

Posted by Nagendra Kumar O V S <na...@ikigo.com>.
HI again
this pdf gives u good start to the validator framework
http://www.manning.com/husted/chap12.pdf

also u can deploy the struts-validator.war that comes with the struts
release and go thro' the jsps, validator.xml, validator-rules.xml

--nagi

-------Original Message-------

From: Struts Users Mailing List
Date: Thursday, July 10, 2003 12:10:40 PM
To: 'Struts Users Mailing List'
Subject: RE: What should be in validate() method when using struts validator
package

Can you please explain how to use validator for client side validations? Any
sample code on the web (links would be helpful).


Thanks
Sriram

-----Original Message-----
From: Nagendra Kumar O V S [mailto:nagendra@ikigo.com] 
Sent: Thursday, July 10, 2003 11:59 AM
To: struts-user@jakarta.apache.org
Subject: Re: What should be in validate() method when using struts validator
package



hi,
struts validator provides both client side as well as server side
validations.
if u want to use the serverside validations , u have to extend the
validatorForm instead of ActionForm and remove the validate() method all
together.
but, in my application, i am using validator for client side validations and
on the server side i still use plain vanilla Action forms and validation
method (for validations) for my own business requirements.
so its a matter of choice.

--nagi

-------Original Message-------

From: Struts Users Mailing <ma...@jakarta.apache.org> List
Date: Thursday, July 10, 2003 11:42:11 AM
To: 'Struts Users Mailing <ma...@jakarta.apache.org> List'
Subject: What should be in validate() method when using struts validator
package

What should be in validate() method when we use Struts Validator package?
Should it be an empty method?

My current validate() method (without using Struts Validator) is as
follows:(What should it be if I implement validations in validator-rules.xml
and validations.xml)? Pl. suggest.

public ActionErrors validate(ActionMapping mapping,
javax.servlet.http.HttpServletRequest request) {
// maintenance forms do new, update and delete, but also searches and create
new for
// fkey resolvers. Only new and update actually need validation.
if (!lrAction_.equals("New") && !lrAction_.equals("Update")) return null;

ActionErrors errs = new ActionErrors();
SupportValues support = new SupportValues();



try {
support.setContactName(contactName_);
} catch (IllegalArgumentException ex) {
errs.add(FLD_CONTACT_NAME,new ActionError("supportviewform
error_contact_name",ex.getMessage()));
}
try {
support.setContactDetail(contactDetail_);
} catch (IllegalArgumentException ex) {
errs.add(FLD_CONTACT_DETAIL,new ActionError("supportviewform
error_contact_detail",ex.getMessage()));
}
try {
support.setPhoneNo(phoneNo_);
} catch (IllegalArgumentException ex) {
errs.add(FLD_PHONE_NO,new ActionError("supportviewform.error_phone_no",ex
getMessage()));
}
try {
support.setEmailAddr(emailAddr_);
} catch (IllegalArgumentException ex) {
errs.add(FLD_EMAIL_ADDR,new ActionError("supportviewform.error_email_addr"
ex.getMessage()));
}
try {
support.setSubject(subject_);
} catch (IllegalArgumentException ex) {
errs.add(FLD_SUBJECT,new ActionError("supportviewform.error_subject",ex
getMessage()));
}
try {
support.setMessage(message_);
} catch (IllegalArgumentException ex) {
errs.add(FLD_MESSAGE,new ActionError("supportviewform.error_message",ex
getMessage()));
} 
if (errs.empty()) return null;

// preserve selected values in the form, so on error don't lose them all.
preserveSelectedValues(request);

return errs;
} // end of validate




____________________________________________________
<http://www.incredimail.com/redir.asp?ad_id=309&lang=9> IncrediMail - Email has finally evolved - <http://www.incredimail.com/redir.asp?ad_id=309&lang=9> Click Here