You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Chetan Pandey <cp...@bluesingapore.com> on 2006/09/27 05:55:07 UTC

How to validate an integer array

Hi All:

 

In my form I have 

 

Int [] roleIds = null.

 

This is used as the Underlying Datatype of a multiple-select Drop-down.

 

Everything works fine but I am not sure how to validate?

 

The following that I tried did not work:

 

<field property="roleIds" depends="validwhen">

             <arg0 key="lms.role"/>

              <var>

      <var-name>test</var-name>

      <var-value> (*this* != 0)</var-value>

    </var>

   </field>  


Re: How to validate an integer array

Posted by Wendy Smoak <ws...@gmail.com>.
On 9/26/06, Chetan Pandey <cp...@bluesingapore.com> wrote:

> Thanks Wendy. I am trying to validate an array of ints.
> The following should be true:
>
> 1. The array is not null.
> 2. The first value in its index should be higher than 0.
> 3. If the first value is 0 then its length must be greater than 2.

I'd just do it in Java code.  It's only a few lines, and is guaranteed
to be easier than trying to convince validwhen to do it.  You can
either write a custom Validator, or else just put it directly in the
validate method, depending on whether you need to reuse it elsewhere.

As I said, I don't believe that validwhen can handle primitive ints.
The grammar file only mentions String and Integer.

-- 
Wendy

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


RE: How to validate an integer array

Posted by Chetan Pandey <cp...@bluesingapore.com>.
Thanks Wendy. I am trying to validate an array of ints.

The following should be true:

1. The array is not null. 
2. The first value in its index should be higher than 0.
3. If the first value is 0 then its length must be greater than 2.

The following validation failed miserably:


  <field property="roleIds" depends="validwhen">
             <arg0 key="lms.role"/>
              <var>
      <var-name>test</var-name>
      <var-value> ((roleIds != null) or ( ( (roleIds[0] == -1) and
(roleIds.length > 1 ) ) or  ( roleIds[0] > 0 ) ) )</var-value>
    </var>
   </field>  
  


Thanks.

Chetan

-----Original Message-----
From: Wendy Smoak [mailto:wsmoak@gmail.com] 
Sent: Wednesday, September 27, 2006 12:15 PM
To: Struts Users Mailing List
Subject: Re: How to validate an integer array

On 9/26/06, Chetan Pandey <cp...@bluesingapore.com> wrote:

> In my form I have
> Int [] roleIds = null.
> This is used as the Underlying Datatype of a multiple-select Drop-down.
> Everything works fine but I am not sure how to validate?
> The following that I tried did not work:
> <field property="roleIds" depends="validwhen">
>              <arg0 key="lms.role"/>
>               <var>
>       <var-name>test</var-name>
>       <var-value> (*this* != 0)</var-value>
>     </var>
>    </field>

I think validwhen only works with String and Integer.  Here's the
ANTLR grammar file:
http://svn.apache.org/repos/asf/struts/struts1/trunk/core/src/main/java/org/
apache/struts/validator/validwhen/ValidWhenParser.g

What are you trying to validate?  Generally, validwhen is used when
validation for one field depends on the value of some other field.

Also, there may be some problems with validwhen and arrays, Google
turned up a couple of mailing list threads and a JIRA issue
(STR-2802).

-- 
Wendy

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






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


Re: How to validate an integer array

Posted by Wendy Smoak <ws...@gmail.com>.
On 9/26/06, Chetan Pandey <cp...@bluesingapore.com> wrote:

> In my form I have
> Int [] roleIds = null.
> This is used as the Underlying Datatype of a multiple-select Drop-down.
> Everything works fine but I am not sure how to validate?
> The following that I tried did not work:
> <field property="roleIds" depends="validwhen">
>              <arg0 key="lms.role"/>
>               <var>
>       <var-name>test</var-name>
>       <var-value> (*this* != 0)</var-value>
>     </var>
>    </field>

I think validwhen only works with String and Integer.  Here's the
ANTLR grammar file:
http://svn.apache.org/repos/asf/struts/struts1/trunk/core/src/main/java/org/apache/struts/validator/validwhen/ValidWhenParser.g

What are you trying to validate?  Generally, validwhen is used when
validation for one field depends on the value of some other field.

Also, there may be some problems with validwhen and arrays, Google
turned up a couple of mailing list threads and a JIRA issue
(STR-2802).

-- 
Wendy

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