• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Struts 2 Validation

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 Kaladhar
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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




Even this is not making any difference.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 689
Scala Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,


You can use this for expression validation.


<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>
 
Bejoy Kaladhar
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Re: client-side expression validator: nothing you do will make client-side expression validation work. It's not supported.

Re: client-side "int" validation--what exactly isn't working?
 
Bejoy Kaladhar
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the correct way is this

use
<field-validator type="fieldexpression"> like this in your example


or

 
Brace yourself while corporate america tries to sell us its things. Some day they will chill and use tiny ads.
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic