0 Replies Latest reply on Nov 5, 2009 5:03 PM by thomasgo

    ValueExpression problem

    thomasgo

      Hi, I have another problem with JBoss EL:


      I read the row index from an A4J repeat tag using <a4j:repeat rowKeyVar="index" ...>.
      Additionally I get the size of the collection using JBoss EL (#{collection.size()}).


      Now, I have a custom tag that checks a condition and renders its children if the condition is met. (If there is a component I could use, I'd ditch my own - but be aware that I can't use SEAM in the current project, so any seam component would not be appropriate).


      My custom component works as long as the expression is quite simple, e.g.
      <mytag:condition value="true"/>,
      <mytag:condition value="#{collection.size() > 0}"/>,
      <mytag:condition value="#{index > 0}"/>
      all work.


      What doesn't work is this: <mytag:condition value="#{collection.size() > (index + 1)}"/>. When I set that expression as the 'rendered' attribute of a nested tag, e.g. <h:outputText rendered="#{collection.size() > (index + 1)}"/> it works, but not with my custom tag.


      Used with my custom tag I get always true for #{collection.size() > (index + 1)} or even for #{collection.size() > (index - 1)} (if the size is > 1) but always false for #{collection.size() > index}


      It seems like the index is ignored and collection.size() is checked against +1 or -1 instead of index + 1 and index - 1.


      Here's the tag handler:


      public class ConditionTagHandler extends TagHandler
      {
        private final TagAttribute condition;
        
        public ConditionTagHandler( TagConfig pConfig )
        {
          super( pConfig );
          condition = getRequiredAttribute( "value" );
        }
      
        public void apply( FaceletContext pContext, UIComponent pParent ) throws IOException, FacesException, FaceletException, ELException
        {    
          Boolean tConditionValue = (Boolean)condition.getObject( pContext, Boolean.class );
          
          if(tConditionValue != null && tConditionValue)
          {
            nextHandler.apply(pContext, pParent);
          }
        }
      }



      Thanks for your help.