You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by James Turner <tu...@blackbear.com> on 2003/03/06 06:56:07 UTC

My dilema: Much improved version of requiredif ready, 1.1 or 1.2?

As I'm sure we've all noticed, the "requiredif" validation, although
seeming to be very popular, is a bear for first time users to
comprehend.  With that in mind, I've just finished a new validation
(which I'm calling "requiredwhen" to avoid confusion), which is much
simpler.  Here's a sample rule:

<field property="firstName" indexedListProperty="dependents" 
       depends="requiredwhen">
  <arg0 key="dependentlistForm.firstName.label"/>
  <var>
    <var-name>test</var-name>
    <var-value>(dependents[].lastName != null)</var-value>
  </var>
</field>

As you can see, you can now put any arbitrary booolean expression as the
test for required.  For example:

((dependents[].lastName == "James") and (options[1] == "true"))

If the parser sees "[]", it replaces it with the indexed property value
of the target field.

Here's the dilema.  I think it's a lot better than "requiredif", will
generate a lot less questions on struts-users, and let people do the
general types of checking they seem to want to do.  Also, since it's
just another rule being added to the Validation set, it shouldn't be
able to destabilize anything else in the release.  However, since it is
a new feature, I hesitate to add it to 1.1 because we're in freeze.

What do other people think?  Also, I used JavaCC to generate the parser,
there's should never be a need to regenerate the java files from the jtt
source, but should someone want to do it, they'd need to download
JavaCC.  Will this be a problem?

James

          New Gig!
 |   |   |   |   |   |   |   |
\|/ \|/ \|/ \|/ \|/ \|/ \|/ \|/
 V   V   V   V   V   V   V   V
Director of Software Development
Benefit Systems, Inc.
jturner@benefit-systems.com

Voice: 603-216-1620
Fax: 317-573-2016 



---------------------------------------------------------------------
To unsubscribe, e-mail: struts-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-dev-help@jakarta.apache.org


Re: My dilema: Much improved version of requiredif ready, 1.1 or 1.2?

Posted by Erik Hatcher <ja...@ehatchersolutions.com>.
Just food for thought:

How about using the OGNL expression language (www.ognl.org) rather than 
writing your own parser?  WebWork, Tapestry, and certainly others, are 
using OGNL.  (and the creator of it is a good friend of mine!)

	Erik

On Thursday, March 6, 2003, at 12:56  AM, James Turner wrote:
> As I'm sure we've all noticed, the "requiredif" validation, although
> seeming to be very popular, is a bear for first time users to
> comprehend.  With that in mind, I've just finished a new validation
> (which I'm calling "requiredwhen" to avoid confusion), which is much
> simpler.  Here's a sample rule:
>
> <field property="firstName" indexedListProperty="dependents"
>        depends="requiredwhen">
>   <arg0 key="dependentlistForm.firstName.label"/>
>   <var>
>     <var-name>test</var-name>
>     <var-value>(dependents[].lastName != null)</var-value>
>   </var>
> </field>
>
> As you can see, you can now put any arbitrary booolean expression as 
> the
> test for required.  For example:
>
> ((dependents[].lastName == "James") and (options[1] == "true"))
>
> If the parser sees "[]", it replaces it with the indexed property value
> of the target field.
>
> Here's the dilema.  I think it's a lot better than "requiredif", will
> generate a lot less questions on struts-users, and let people do the
> general types of checking they seem to want to do.  Also, since it's
> just another rule being added to the Validation set, it shouldn't be
> able to destabilize anything else in the release.  However, since it is
> a new feature, I hesitate to add it to 1.1 because we're in freeze.
>
> What do other people think?  Also, I used JavaCC to generate the 
> parser,
> there's should never be a need to regenerate the java files from the 
> jtt
> source, but should someone want to do it, they'd need to download
> JavaCC.  Will this be a problem?
>
> James
>
>           New Gig!
>  |   |   |   |   |   |   |   |
> \|/ \|/ \|/ \|/ \|/ \|/ \|/ \|/
>  V   V   V   V   V   V   V   V
> Director of Software Development
> Benefit Systems, Inc.
> jturner@benefit-systems.com
>
> Voice: 603-216-1620
> Fax: 317-573-2016
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-dev-help@jakarta.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-dev-help@jakarta.apache.org


RE: My dilema: Much improved version of requiredif ready, 1.1 or 1.2?

Posted by James Turner <tu...@blackbear.com>.
Actually, I realized just after I sent this that if I took the required
part out and called it validwhen instead, you end up with a true general
purpose validation tool!  So that's the one I'm proposing.  Basically,
if you had a field lastName that was required if firstName was filled
in, you say:

((lastName != null) or (firstName == null))

I.e., the field is valid if it isn't null, or the firstName field is
null.

This means you can generate an error on a field based solely on the
values of other fields.

James



---------------------------------------------------------------------
To unsubscribe, e-mail: struts-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-dev-help@jakarta.apache.org