5 Replies Latest reply on Jan 19, 2007 9:54 AM by Pete Muir

    <s:validateAll> and "Advanced Facelets Programming". Is it a

    Vladimir Kovalyuk Apprentice

      I was impressed by http://www-128.ibm.com/developerworks/web/library/j-facelets2.html

      I tried to implement similar approach but I got StringOutOfRangeException.
      That was the first problem with Validators class. It is in the following string:

      String modelExpression = propertyExpression.substring(0, dot) + '}';

      When I use #{object[property]} syntax, dot is -1 and exception is raised.

        • 1. Re: <s:validateAll> and
          Pete Muir Master

          Can you post the facelet you are trying to get working?

          • 2. Re: <s:validateAll> and
            Vladimir Kovalyuk Apprentice

            I fixed some lines in that class got NPE.
            I realized that validate() takes script component tag parameters instead of evaluated expression. I debugged a lot JSF RI 1.2 and EL and realized that EL defers evaluation. Thus by calling valueBinding.getExpressionString() in ModelValidator.validate() Seam obtains just expression as it looks like but not as it should be evaluated.
            I don't see a workaround. I commented <s:validateAll> and now all works fine except hibernate validators. But I love this feature in Seam and will count on it in the future.

            Some excerpts from my code:
            source tag:

             <c:if test="#{empty id}">
             <c:set var="id" value="#{name}"/>
             <c:if test="#{empty readonly}">
             <c:set var="readonly" value="#{details.readonly}"/>
             <!-- detect type of editor -->
             <c:if test="#{empty editor}">
             <c:set var="editor" value="#{my:detectEditor(object, name)}"/>
             <!-- insert controls -->
             <c:if test="#{editor == 'text'}">
             <h:inputText id="#{id}" value="${object[name]}" readonly="#{readonly}">
             <c:if test="#{editor == 'textarea'}">
             <h:inputTextarea id="#{id}" value="#{object[name]}" readonly="#{readonly}">
             <c:if test="#{editor == 'selectBooleanCheckbox'}">
             <h:selectBooleanCheckbox id="#{id}" value="#{object.name}" readonly="#{readonly}">

            how tag is used:
            <my:property object="#{details.object}" name="name"/>

            As the result expression string is "object[name]". But facelets calculates it as #{details.object.name}
            NPE is due to the fact that there is no "object" in searchable contexts.

            Please give me an advice how to work around this problem.

            • 3. Re: <s:validateAll> and
              Pete Muir Master

              As I suspected ;) There is AFAIK no way around the problem.

              As you say, what needs to happen is that you need to be able to ask EL to give you the final expression for expression, but there is no functionality in EL for this.

              I know Jacob is aware of this problem and I think he is working on a new version of EL so hopefully that will fix this.

              The only way I know to get around this is to extend model validator and make it take a string that references the bean.property to validate against.

              • 4. Re: <s:validateAll> and
                Vladimir Kovalyuk Apprentice

                Bad news :(

                I don't want to rewrite UiValidateAll, but it seems that it is the only way.
                I haven't realized yet how to build the expression. Probably I will need to access to private field "orig" in some class. It keeps the original expression. It won't be difficult to traverse all the ASF classes and build the final expression.
                At least I hope that it is possible.

                • 5. Re: <s:validateAll> and
                  Pete Muir Master

                  It would be great if you can post back any success you have :)