Issue Details (XML | Word | Printable)

Key: STR-2802
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Unassigned
Reporter: Oudot Christophe
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Struts 1

Validator validwhen cannot test between two different indices in array

Created: 18/Mar/06 12:54 AM   Updated: 05/Jun/08 06:18 AM
Return to search
Component/s: Core
Affects Version/s: 1.2.8
Fix Version/s: 1.3.10, 1.4.0

Environment:
Operating System: Windows 2000
Platform: PC

Bugzilla Id: 39020


 Description  « Hide
This code in the validator.xml fails with this error : "unexpected token adr.."

  
<field property="adr[0]" depends ="validwhen">
  <var>
      <var-name>test</var-name>
      <var-value>((*this*!=null) or (adr[1] != null ))</var-value>
  </var>
</field>


adr is an array of two adress lines. Only one of them needs tobe filled.
According to the document of the validator, it should work.

 All   Comments   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Niall Pemberton added a comment - 18/Mar/06 01:02 AM
Adding a link to the related thread on the user list:

http://www.mail-archive.com/user%40struts.apache.org/msg43177.html

I had a quick look at the source (ValidWhenParser.g) and I agree it looks like
it should cater for this. I also tried adding a test case (to
TestValidWhen.java) to and got the same result as Christophe.

Eric Rizzo added a comment - 21/Aug/06 05:05 PM
Is there any workaround for this bug? I have a similar requirement (need to check for presence of EITHER one field or at least one item in an array field (items selected from an HTML list), but have run into the same issue.
Is there any other way to configure the validator to do this kind of check, at least until this bug gets fixed?

Laird Nelson added a comment - 05/Mar/07 05:09 PM
It's now March 2007; I was wondering if any progress had been made on this bug. I am working on struts 1.3.5, and I encounter the same issue with the following code:

<var-value>((*this* != null) or ((govIDParts[0] == null) and (govIDParts[2] == null)))</var-value>

Niall Pemberton added a comment - 05/Mar/07 05:39 PM
I doubt anyones looking at this - It needs someone to come forward with a patch to fix it

Henri Yandell added a comment - 06/Mar/07 05:18 PM
Do you still have your test case Niall?

Niall Pemberton added a comment - 06/Mar/07 06:19 PM
I didn't (I changed machines since then) - but I've re-created one and committed it:

http://svn.apache.org/viewvc?view=rev&revision=515237

Henri Yandell added a comment - 15/Mar/07 10:01 PM

I suspect that the third of the array rules shouldn't have the LBRACKET on the end of it. The problem with both Niall's test and the original report is that neither of them match one of the 5 array rules.

ie:

Index: ValidWhenParser.g
===================================================================
--- ValidWhenParser.g (revision 518754)
+++ ValidWhenParser.g (working copy)
@@ -182,7 +182,7 @@
             Object i3 = argStack.pop();
             argStack.push(ValidatorUtils.getValueAsString(form, i3 + "[" + i4 + "]" + i5));
 }
-| identifier LBRACKET integer RBRACKET LBRACKET {
+| identifier LBRACKET integer RBRACKET {
             Object i7 = argStack.pop();
             Object i6 = argStack.pop();
             argStack.push(ValidatorUtils.getValueAsString(form, i6 + "[" + i7 + "]"));

Henri Yandell added a comment - 21/Mar/07 05:59 AM
 svn ci -m "Fixing STR-2802 by removing the unnecessary LBRACKET. Test now passes and I don't understan
d what the LBRACKET would have been there for so I think it was just an error that's been in there forever and ever. " src/
Sending src/main/java/org/apache/struts/validator/validwhen/ValidWhenParser.g
Sending src/main/java/org/apache/struts/validator/validwhen/ValidWhenParser.java
Transmitting file data ..
Committed revision 520763.

Niall Pemberton added a comment - 10/Sep/07 10:41 PM
The fix for STR-3088 has also back-ported the fix for this issue into the 1.3 Branch - see revision 569606:

http://svn.apache.org/viewvc?view=rev&revision=569606