1 Reply Latest reply on Jun 21, 2007 7:19 AM by cba2

    Alternate property reference style in EL not working

    pgmjsd

      It looks like http://jira.jboss.org/jira/browse/JBSEAM-580 has resurfaced.

      I'm using Seam 1.2.1.GA and I get a String index out of bounds exception when I use the alternate syntax for referencing an entity property:

      #{entity[fieldName]}


      Here is the stack trace:
      18:57:39,147 ERROR [STDERR] java.lang.StringIndexOutOfBoundsException: String index out of range: -1
      18:57:39,148 ERROR [STDERR] at org.jboss.seam.ui.ModelValidator.validate(ModelValidator.java:32)
      18:57:39,148 ERROR [STDERR] at javax.faces.component._ComponentUtils.callValidators(_ComponentUtils.java:157)
      18:57:39,148 ERROR [STDERR] at javax.faces.component.UIInput.validateValue(UIInput.java:312)
      18:57:39,148 ERROR [STDERR] at javax.faces.component.UIInput.validate(UIInput.java:353)
      ...
      


      Basically, the following method in Expressions.java throws because 'dot' is -1:
       public InvalidValue[] validate(String propertyExpression, Object value)
       {
       int dot = propertyExpression.lastIndexOf('.');
       int bracket = propertyExpression.lastIndexOf('[');
       if (dot<=0 && bracket<=0)
       {
       return new InvalidValue[0];
       }
       String componentName;
       String propertyName;
       if (dot>bracket)
       {
       componentName = propertyExpression.substring(2, dot);
       propertyName = propertyExpression.substring( dot+1, propertyExpression.length()-1 );
       }
       else
       {
       componentName = propertyExpression.substring(2, bracket);
       propertyName = propertyExpression.substring( bracket+1, propertyExpression.length()-2 );
       }
       String modelExpression = propertyExpression.substring(0, dot) + '}';
      
       Object modelInstance = createValueBinding(modelExpression).getValue(); //TODO: cache the ValueBinding object!
       return getValidator(modelInstance, componentName).getPotentialInvalidValues(propertyName, value);
       }
      


      Does anyone know of a way to work around this? I'm trying to make a generic Facelets tag for input fields and I can't because it won't let me bind to a property using this syntax.