Hello experts, I'm am stuck with a issue in struts 2 validation can you please help me sort out this.I had implemented client side validation on struts 2 and i am successful in using validators as required,requiredString,stringLength but now facing 2 basic issues now
1.I'm not able to use the expression validator 2.i need to check first whether a text box is empty or not if empty it should give a validation message also if it contains any value other than integer then also it should give a message
My code snippets are here Struts.xml
this is my validation xml file CarClubAction-carClubSave-validation.xml
also in my jsp page i've given all my controls within a forma tag as
Any idea what the problem could be?
Bejoy.K.S
Bejoy Kaladhar
Greenhorn
Joined: Jul 09, 2008
Posts: 9
posted
0
Also i tried a few options for my second issue, using required and int
1.with and without short-circuit="true" in both the validators 2.using requiredString validator instead of required validator
unfortunately even that is not working.
With the expression validator i've tried a few options as
The expression validator is not supported on the client side; that would require a clinet-side version of OGNL and access to server-side domain objects. It wouldn't be impossible to implement, but it would take effort.
I have a patch going in to allow manually-configured custom client-side validation that you could use to accomplish this; follow the Struts-user mailing list to see when it goes in--I'm anticipating tomorrow, but it could be as late as Friday. The patch *should* work with earlier versions of Struts 2 as well; assuming it does I'll put it in both the S2.0 and S2.1 branches.
Your second issue is likely to be caused by providing useless parameters to the "int" field-validator; you're giving it "minLength" and "maxLength"--length has no meaning to an integer validation. You need to use the "min" and "max" parameters.
<field name="userId"> <field-validator type="stringlength"> <param name="minLength">3</param> <param name="maxLength">50</param> <message> User ID must be between ${minLength} and ${maxLength}. </message> </field-validator> <field-validator type="regex"> <param name="expression">^[0-9a-zA-Z\-._]*$</param> <message>User Id contains only characters A-Z, a-z, 1-9, ., _, -.</message> </field-validator> </field>
For check equality user this :
<validator type="expression"> <param name="expression"> user.password eq confirmPassword </param> <message>Confirm password should be same as password.</message> </validator>
hello guys,sorry for a late response.met with an accident tats why. ok..Nishan i tried the expression validator the way you specified using equals(eq) but sory to ay that the validation is not being performed i gave it as
the senario is that i'm having a select which contains a list of cities.The first element of the list is "Select City" . I need to validate whether a ciy has been selected or not i mean if the citySelect slect box is having the value "Select City" then the message should be displayed
Initially i tried the expression validaor as
but these 3 didn't work so i created text field like this within my form
and gave the validator expression as
Unfortunately even that is not working.any thoughts? [ December 19, 2008: Message edited by: Bejoy KS ]
Bejoy Kaladhar
Greenhorn
Joined: Jul 09, 2008
Posts: 9
posted
0
Hello David It was a typing mistake form my side i had tried the int validation with parameters "min" and "max" only.It is not working with the short-circuit.any intelligent solutions?
hi, I need to check whether a text field is empty or not.If not empty then i need to check whether that it is a number beteen 1 and 10.If empty it should show "Enter a value for field".if Any value other than nos beteen 1 and 10 is entered then it should show "Enter a value between 1 and 10".This is exactly how i need my validation to work. I tried out this as
When I "what exactly isn't working" I mean "describe the behavior you're seeing, and compare it to the behavior you're expecting".
Bejoy Kaladhar
Greenhorn
Joined: Jul 09, 2008
Posts: 9
posted
0
ok David.Sorry for confusing you. When i validate with the required validator alone i get the validation done also the validation works fine when i use the int validator alone
But when both are used in the order i mentioned only the required validator works and the int validator doesn't.ie if i dont give any value then it prompts for a value but if i give a string value it accepts it rather than prompting for an int value.This is my short stopper right now.
deep kathuria
Greenhorn
Joined: Jun 13, 2011
Posts: 2
posted
0
the correct way is this
use
<field-validator type="fieldexpression"> like this in your example