Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Unable to validate minlength

 
Luke Zechariah
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • 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: 129
  • Mark post as helpful
  • send pies
  • 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.
 
Ergin Er
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • 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: 129
  • Mark post as helpful
  • send pies
  • 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.
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!