Win a copy of Spring Boot in Practice this week in the Spring forum!
  • 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
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Unable to validate minlength

 
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In struts-validation, I am able to validate for "required" field on client side as well as server side. But if I want the field to be validated for a "minlength", I am unable to do it.

It is giving me an error, when validating for minlength:

Title Size can not be less than null characters.

Following is my .properties file:






Does anybody knows the answer for this. Thank you very much in advance.

Lk.
 
Luke Zechariah
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I found the answer to this, the dtd to which the validation.xml and validation-rules.xml were pointing is a previous version. So just changed and it validates if the field is less than 3 characters.

But now I have got another error:
Now even if I enter 4 or more characters still I am getting the same error:
"Title Size can not be less than 3 characters."

Does anyone has any ideas abt this? Thanks for your time.
 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you sure you got the name of the variable right?
You define that a field needs to match 2 variables: required,minlength. Then you define a minlen?
 
Luke Zechariah
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ergin,

Thanks for the reply. What you said was correct, the var:minlen is wrong, I defined it as var:minlength and its working.

But I have another problem now: I wanted to implement my own custom minlength validation as follows:

So I named it as "var:minfldlength", it is validating properly. But it was always gives the output as

"Title Size can not be less than null characters"

I do not know and I have tried all my best still the "null" is not taking the value "3" or whatever is used. But if I enter more than 3 chars, it validates properly and does not show any error.

See the code:

It is able to identify {0} from the properties file but not {1}. I do not know why.
I also tried using

still does not work.

This is the validation-rules.xml

The version of dtd I am using is validator_1_1_3.dtd

The custom Code for MinFldLength is as follows:


I do not know where the catch no matter how many ever times I try it gives my the same error:
TITLE SZE can not be less than null characters

Praise the Lord, finally just now as I was writing to this forum, I got this idea and that solved my puzzle:
In the validation-rules: I forgot to put this attribute in "validator" node:

jsFunctionName="org.apache.commons.validator.javascript.validateMinLength"

Now I ran it and its working awesome.

Thanks for all the suggestions,
Lk.
 
reply
    Bookmark Topic Watch Topic
  • New Topic