File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes Validator with 3 fields, 1 element required Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Validator with 3 fields, 1 element required" Watch "Validator with 3 fields, 1 element required" New topic

Validator with 3 fields, 1 element required

Manuel Sanchez Iba�ez

Joined: Jul 12, 2005
Posts: 20
Hello and sorry for my english. I have an form with 3 field (type Multibox) where user can select or not select, but must select at least one in total

//Situaciones Juego Ataque
<html:multibox property="sjuegoa" value="1x0"/>1x0
<html:multibox property="sjuegoa" value="1x1"/>1x1
<html:multibox property="sjuegoa" value="1x2"/>1x2

//Situaciones Juego Defensa
<html:multibox property="sjuegod" value="1x0"/>1x0
<html:multibox property="sjuegod" value="1x1"/>1x1
<html:multibox property="sjuegod" value="1x2"/>1x2

//Situaciones Juego Mixto
<html:multibox property="sjuegom" value="1x0"/>1x0
<html:multibox property="sjuegom" value="1x1"/>1x1
<html:multibox property="sjuegom" value="1x2"/>1x2

I have seen Struts have the rule "validwhen" but my code don�t work fine. For example, i trying check at least Atack or Defend aren�t null:

<field property="sjuegoa" depends="validwhen">
<arg0 name="validwhen" key="campo.situaciones"/>
<var-value>(sjuegod == null) and (*this* == null)</var-value>

<field property="sjuegod">
<arg0 key="campo.sjuegod"/>

This code work semi-fine, the message i need appear but in console appear:

line 1:19: expecting EOF, found 'and'
at antlr.Parser.match(
at org.apache.struts.validator.validwhen.ValidWhenParser.expression(

If i put brackets, the error don�t appear but the message that i need don�t appear:

<var-value>((sjuegod == null) and (*this* == null))</var-value>

�Any idea? I use Struts 1.2.4
Marc Peabody
pie sneak

Joined: Feb 05, 2003
Posts: 4727

You need to put the arg/key tag within the tags that do the validating. You are putting it in a separate tag that does no validation.

A good workman is known by his tools.
Manuel Sanchez Iba�ez

Joined: Jul 12, 2005
Posts: 20
I don�t understand your idea. Finally, i have written other validation in validation-rules.xml and i can verify well that 3 fields aren�t null.

Thanks for your interest.
I agree. Here's the link:
subject: Validator with 3 fields, 1 element required
jQuery in Action, 3rd edition