On Sat, 15 Jan 2005 15:08:17 -0500, Todd Nine <[EMAIL PROTECTED]> wrote:
> Hi All,
>   I am having trouble getting my mind around the boolean expression
> semantics of the validwhen validator.  Consider the following example.
> 
> I have a form with two possible input groups depending on the user
> selection.  If the entity is an individual, then I need to require
> firstName etc.  If the entity is a business then I need to require a
> business name.  Below is my validation code.
> 
> <field property="firstName" depends="validwhen, mask">
>        <arg0 key="prompt.common.firstName" />
>        <var>
>                <var-name>mask</var-name>
>                <var-value>${alphaname}</var-value>
>        </var>
>        <var>
>                <var-name>test</var-name>

If the "test" evaluates to false then it results in an ActionError.
(JavaDocs : Checks if the field matches the boolean expression
specified in test parameter.)


>                <var-value>(entityType == "individual")</var-value>

This says that if entityType is "individual" then this property
("firstName") satisfies this condition no matter what the value of
"firstName" is. On the otherhand if entityType == "business" then this
condition evaluates to false and so this property ("firstName") is
tagged as required by the validator. (You should get this message even
if you specify something for "firstName")

>        </var>
> </field>
> 
> <field property="lastName" depends="validwhen, mask">
>        <arg0 key="prompt.common.lastName" />
>        <var>
>                <var-name>mask</var-name>
>                <var-value>${alphaname}</var-value>
>        </var>
>        <var>
>                <var-name>test</var-name>
>                <var-value>(entityType == "individual")</var-value>
>        </var>
> </field>
> 
> <field property="ssn" depends="validwhen, mask">
>        <arg0 key="prompt.common.ssn" />
>        <arg1 key="prompt.common.ssn.format" />
>        <var>
>                <var-name>mask</var-name>
>                <var-value>${ssn}</var-value>
>        </var>
>        <var>
>                <var-name>test</var-name>
>                <var-value>(entityType == "individual")</var-value>
>        </var>
> </field>
> 
> <field property="birthDate" depends="validwhen, date">
>        <arg0 key="prompt.common.birthDate" />
>        <var>
>                <var-name>datePatternStrict</var-name>
>                <var-value>${date}</var-value>
>        </var>
>        <var>
>                <var-name>test</var-name>
>                <var-value>(entityType == "individual")</var-value>
>        </var>
> </field>
> 
> <field property="businessName" depends="validwhen, mask">
>        <arg0 key="prompt.common.businessName" />
>        <var>
>                <var-name>mask</var-name>
>                <var-value>${alphaname}</var-value>
>        </var>
>        <var>
>                <var-name>test</var-name>
>                <var-value>(entityType == "business")</var-value>
>        </var>
> </field>
> 
> However when "business" is the entityType, firstName, lastName, ssn,
> and birthDate show up as required in the error messages.  When the
> entityType is "individual" businessName shows up.  I thought that the
> value was reversed in the jsp, hence reversing it when it is being set
> into the form.  I debugged the validate method and the enityType is
> being set correctly.  This operand seems sufficient to work correctly.
> However changing all of the == to != seems counterintuitive to me.

Even if specify something like this, 
<field property="firstName" depends="validwhen, mask">
       <arg0 key="prompt.common.firstName" />
       <var>
               <var-name>mask</var-name>
               <var-value>${alphaname}</var-value>
       </var>
       <var>
               <var-name>test</var-name>
               <var-value>(entityType != "individual")</var-value>
       </var>
</field>

it doesn't work as you expect it to, as you can see it fails when
entityType is "individual".

So, the right way of specifying the conditionals is to think about
when you don't need that property. For example another of saying
"firstName" is required when "entityType = individual" is "firstName"
is required unless "entityType = business"
 
so now you conditional would be 
<field property="firstName" depends="validwhen, mask">
       <arg0 key="prompt.common.firstName" />
       <var>
               <var-name>mask</var-name>
               <var-value>${alphaname}</var-value>
       </var>
       <var>
               <var-name>test</var-name>
               <var-value>(entityType == "business") or
(*this*!=null)</var-value>
       </var>
</field>

Which says if entityType="business" firstName is not required
otherwise (entityType !="business" implicity entityType="individual")
this(firstName) is required
 
> It seems to me that my logic should work.  {firstName} is required
> when {entityType} == "individual".  Can someone explain the semantics
> of the need to negate all of the expressions?
> 
> Thanks,
> Todd
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to