• 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
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Question about the required validator

 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In reading 'Struts in Action' (I just realized that the name is a play on words - aren't I slow...), I came across the following sentence in the section describing the 'required' validator:
Since browsers do not submit empty fields, any field that isn�t required will skip
all validations if the field is null or has a length of zero.

I have read this through many times now, but I'm lost. Could someone please explain what Mr Husted is getting at?
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
any field that isn�t required will skip all validations if the field is null or has a length of zero
For example, if my rules state that a field is required and must be a valid email format, then if the field is empty, an ActionError will be created.
If my rules state that a field is not required and it must be a valid email format, then if the field is empty, it's not checked against the proper email format, but if the field is not empty, the value entered into it must match a valid email format.
Clear?
 
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Wow, I can't believe I've never caught that sentence. It doesn't make a whole lot of sense for a number of reasons.
For starters, browsers do submit empty text fields as an empty String "". (Note that I'm talking text fields, checkboxes are another story.) In addition, declaring a field as depends="email" or any other built-in validation will still run the required validation by default. Just take a look at validator-rules.xml - they all depend on required. So if you declare a field with depends="email" it will still function as depends="required, email"!
 
Sean Walker
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Dirk, that was quite helpful until I read Marc's post. At least it clarified what the author meant. However, what Marc said seems to be in conflict with this. Specifically, since most of the basic validators imply the required validator, how can a rule using a basic validator not be required?
Also, as Marc points out, I also understood that unchecked checkboxes are the only field type that are not present in form submissions.
 
Sheriff
Posts: 17734
302
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not sure which validator-rules.xml is looking at but the one that I have has depends="" for most of the basic validators, email included. Only exception are the range validators. What Dirk said sounds right to me.
 
Marc Peabody
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, I just downloaded a fresh copy of 1.1 and it's depends="". So, my apologies on that one. I very well could have tweaked mine a while ago and forgot about it.
Still, the "Since browsers do not submit empty fields," part of the sentence could be omitted.
 
Sean Walker
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think they must have dropped the required dependencies on the basic validators in a recent release of the Validator package, because Ted Husted wrote in his book Struts in Action that most of the basic validators are declared dependent on the required validator.

Like most of the other standard validators, the mask validator is declared to be dependent on the required validator. Therefore, if a field depends on both required and mask, then the required validator must complete successfully before the mask validator is applied.


[ April 29, 2004: Message edited by: Sean Walker ]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic