Results 1 to 10 of 10
Thread: Struts validator framework
- 07-14-2008, 02:10 PM #1
Member
- Join Date
- Jul 2008
- Location
- chennai
- Posts
- 9
- Rep Power
- 0
Struts validator framework
Hi friends,
Im new to struts framework and using struts1.3
thing is i want to do client side validation using validator framework.
server side validation (ie <html:erros> ) is working fine.but not client side validation.
im using <html:javascript formName="Homeform">
and <html:form action="/action.do" method="post" onsubmit="return validateHomeform(this);">
Homeform is bean which extends ValidatorForm..
but im not getting alertbox n all.can u guys pls help me
If u r not able to understand means i can explain in detail.
Lukin forward ur answers.
- 07-15-2008, 12:27 PM #2
Member
- Join Date
- Jul 2008
- Posts
- 6
- Rep Power
- 0
Hi you need to do the Homeform fields for client side validation using validation.xml file.
for eg.........
assume passwordfied and confirm password fields
<form name="Homeform">
<field property="password" depends="required,minlength">
<arg0 key="home.password"/>
<arg1 key="${var:minlength}" name="minlength" resource="false"/>
<var>
<var-name>minlength</var-name>
<var-value>6</var-value>
</var>
</field>
<field property="confirmpassword" depends="validwhen">
<msg name="validwhen" key="errors.confirmpassword.match"/>
<var>
<var-name>test</var-name>
<var-value>(*this* == password)</var-value>
</var>
</field>
In Properties file
home.password=password
errors.confirmpassword.match=password does not match
try to this logic you can get the output
- 07-15-2008, 01:05 PM #3
Member
- Join Date
- Jul 2008
- Location
- chennai
- Posts
- 9
- Rep Power
- 0
Hi ganesan..thx much 4 ur reply.
but i already defined validation.xml like this for "required" validation
<form-validation>
<formset>
<form name="HomeForm">
<field property="filepath" depends="required">
<arg key="required.index" />
</field>
</form>
i hav properties file also..
and my validator-rules.xml looks like this
- 07-15-2008, 01:08 PM #4
Member
- Join Date
- Jul 2008
- Location
- chennai
- Posts
- 9
- Rep Power
- 0
(CONTINUATION)
<validator name="required"
classname="org.apache.struts.validator.FieldChecks "
method="validateRequired"
methodParams="java.lang.Object,
org.apache.commons.validator.ValidatorAction,
org.apache.commons.validator.Field,
org.apache.struts.action.ActionMessages,
org.apache.commons.validator.Validator,
javax.servlet.http.HttpServletRequest"
msg="errors.required"/>Last edited by Satheeshhere; 07-15-2008 at 01:25 PM.
- 07-15-2008, 01:26 PM #5
Member
- Join Date
- Jul 2008
- Location
- chennai
- Posts
- 9
- Rep Power
- 0
server side validation is working very fine..
but stil couldnt get client side alert box.
i think there s some thing wrong in my validatior-rules.xml for only client side validation.
is it?
Ganesh pls im awaitin for ur reply.thx in advance:)
- 07-15-2008, 02:49 PM #6
Member
- Join Date
- Jul 2008
- Posts
- 6
- Rep Power
- 0
Hi satheesh
you should copy the validator error message from validator-rules.xml to properties file.
1. In form bean u must extend ValidatorForm
2. u put the plugins in struts-config.xml
3. define the validation rules in validation.xml(for eg i was send previouse message)
4. you need not to any change in validator-rules.xml file
5.call java script code in jsp file
follow this sure you can get the output
Regards
Ganesh
- 07-15-2008, 02:59 PM #7
Member
- Join Date
- Jul 2008
- Location
- chennai
- Posts
- 9
- Rep Power
- 0
Hi ganesh.
i have done all those things as u said properly.so that only my server side validation s working fine.
thing is validator-rules.xml wat i have has some errors..
Can you just send your validatior-rules.xml? it wil be helpful if u do that..
- 07-25-2008, 12:48 PM #8
Member
- Join Date
- Jul 2008
- Posts
- 3
- Rep Power
- 0
Make sure the javascript formname similar to the <form-bean> name mentioned in the struts config.xml file.
- 08-05-2008, 06:16 AM #9
Member
- Join Date
- Dec 2007
- Posts
- 42
- Rep Power
- 0
For client side I think the javascript code should be used,what you have done using the validation.xml is processed on the server and so ur server side validation is working.Then go for javascript as used in almost all sites.Define the javascript method and call them when the form is submitted or some thing change happens in the form elements.
- 08-19-2008, 04:44 AM #10
Member
- Join Date
- Aug 2008
- Posts
- 1
- Rep Power
- 0
Today I have the same problem, I'm using Struts1.1, its validator-rule.xml dtd is 1.0.
I found you are validating a 'password' field, then I came across the problem that it can't alert a message when the field'e length is less then 'minlength' I defined in validation.xml. You can find the javascript code of function validateMinlength() in validator-rule.xml, there is a piece of follows:
if (field.type == 'text' || field.type == 'textarea')
so it won't validate field of 'password' type, you can change it to
if(field.type == 'text' || field.type == 'textarea' || field.type == 'password')
then it will work fine. I'm not sure whether it is a bug or there is some other reasons.
Similar Threads
-
Struts Validator validwhen
By getsridhara in forum Web FrameworksReplies: 0Last Post: 05-30-2008, 10:58 AM -
Struts Validator
By anoop.retnakumar in forum Web FrameworksReplies: 1Last Post: 03-05-2008, 06:54 AM -
Struts Validator Framework
By Albert in forum Web FrameworksReplies: 2Last Post: 02-15-2008, 11:01 AM -
Struts Validator - JScript version of Validator ´validwhen´
By Felissa in forum Web FrameworksReplies: 1Last Post: 07-06-2007, 04:39 PM -
Validator framework
By Daniel in forum Web FrameworksReplies: 1Last Post: 06-25-2007, 05:29 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks