read the bottom of your email!
Gujral, Irvind [EMAIL PROTECTED] on 11/02/2001
03:23:50 PM
Please respond to Struts Developers List
[EMAIL PROTECTED]
To: 'Struts Developers List'
[EMAIL PROTECTED]
cc:(bcc: David Hay/Lex/Lexmark)
Subject: Unsubscribe me
Unsubsribe me!!
-Original Message-
From: David Winterfeldt [mailto:[EMAIL PROTECTED]]
Sent: Friday, November 02, 2001 2:17 PM
To: Struts Developers List
Subject: RE: Validator design considerations
--- Sobkowski, Andrej [EMAIL PROTECTED]
wrote:
Ted,
thanks for your answer.
I understand your idea of initial validation. And
I also agree with
Generally, objects should have dominion over their
own data. But in the
case of the validation process, IMHO the bean is the
data used by a
potentially external validation process (and not
vice-versa). What if the
validation on the same bean is different depending
on the app context? It
wouldn't be clean (for lack of better word) to
consider both validations
inside the bean itself (validate())... hence the
advantage of having
separate validation processes on the same bean
(related to different app
contexts i.e. different actions). Am I missing the
point?
Since the ActionForm is directly associated to the
form, it wouldn't necessarily be shared. But a pure
Address JavaBean could be shared by two ActionForms by
using nested properties.
We could definately use more standard, backend
validators, but,
personally, I would say that the framework object
that calls the
standard validator with the property in question
should be the
ActionForm, or a business object, and not the
Action or ActionServlet
directly.
In the current Struts version, the validate() on the
FormBean is called by
the ActionServlet.performValidate(...) method, isn't
it? The validation is
part of the whole process that is controlled by the
ActionServlet - from a
procedural point of view - and the same applies if
the validate() is in
the FormBean or in the Action (the call is simply
made on different entities
but in the same place). Or not?
A salomonic suggestion :) we could have different
levels of validators:
bean-related and action-related. The first ones will
take care of
first-level validations that always apply to the
bean; the second will be
context-specific and called only if the first
validations passed. But by
separating the validation process (by taking it out
of the bean itself), it
would be possible to dynamically associate a
validation process (validator)
with a bean/action.
The association of a bean with a set of validation
rules is purely based on the form element's name
attribute (the key) and the value you pass into the
Validator when you initialize it to run. Most people
use the ValidatorForm which associates the this to the
name of the form (mapping.getAttribute()). But you
could extend the ValidatorForm and use anything for a
key and make dynamic associations if you wanted too.
You could even apply a basic default bean validation
and then a custom one.
Example in struts-config.xml:
!-- Global validators: pre-defined group of
validators --
global-validator name=myValidator
validation ... /
validation ... /
/global-validator
!-- Bean-specific validations --
form-bean name=myForm
type=com.mycompany.myFormBean
validation property=... / (see previous message
for details)
validation property=... /
/form-bean
!-- Dynamic link to global validator --
form-bean name=myForm2
type=com.mycompany.myFormBean2
validation link=myGlobalValidator / (link to
validator defined above)
/form-bean
!-- Action-specific validation --
actionpath=/myPath
type=com.mycompany.myActionWithValidation
name=myForm
validation property=... / (see previous message
for details)
/action
Again, in my personal opinion, all of the above
would be cleaner by
separating the validators from the beans themselves.
Did I manage to change
your mind? :)
If the ActionForm was just a pure data bean I would
agree, but it isn't really. There are already a
number of layers to the current system to add and
customize funcionality. I do like the idea of having
a base set of validations you could define and
reference.
David
Andrej
-Original Message-
From: Ted Husted [mailto:[EMAIL PROTECTED]]
Sent: Friday, November 02, 2001 12:40 PM
To: Struts Developers List
Subject: Re: Validator design considerations
Andrej Sobkowski wrote:
- The form bean itself is a special data holder
and shouldn't be aware
of
how its data is validated. Do you agree?
I'm not sure that I do. I like to think of the
ActionForm as a firewall.
If it has passes the intial validation, then I know
it is safe to use,
and can passed along to business methods. Generally,
objects should have
dominion over their own data.
Under the current model, the bean is not even passed
to the Action