2 Replies Latest reply on Dec 16, 2010 4:33 PM by Steven De Groote

    Refresh jsf validator component on rerender

    Steven De Groote Newbie

      Hi,

      I have an issue with the attributes values of a validator component.
      Apparently the validator is created when I first visit a page.

      Please see my code below:

       

      <h:inputText value="#{qsetting.value}" rendered="#{qsetting.dataType=='Double'}"> 

          <mw:validateRange min="#{qsetting.minValue}" max="#{qsetting.maxValue}" />
      </h:inputText> 



      The inputText component is reRendered through ajax (with a4j:support) but apparently, including the value that is displayed.
      Unfortunately, the qsetting.minValue and qsetting.maxValue are not refreshed, causing my validator to not work correctly.

      Is there a possibility to refresh the validator, to make sure it  re-retrieves its attributes or to just create a new instance of the  validator?
      The validator class itself is currently implementing "Validator, Serializable".
      Also, I'm using jsf1.2 with facelets...

      Thanks,
      Steven

        • 1. Re: Refresh jsf validator component on rerender
          Nick Belaevski Master

          Steven,

           

          It''s not clear, what mw:validateRange is, but if it's an extension of standard JSF validator, then the problem can be caused by the fact, that validators operate with values and not ValueExpression objects. So, when view is built, expressions are evaluated, and values are persisted in view state until view is rebuilt (e.g. on navigation). As a workaround, invoke validate(...) method inside your bean or implement custom validator that will be using ValueExpression.

          1 of 1 people found this helpful
          • 2. Re: Refresh jsf validator component on rerender
            Steven De Groote Newbie

            Hi Nick,

             

            thanks for the reply. At least I have some kind of an explanation now.

            However, my validator is simply a class RangeValidator implements Validator, Serializable.

            If relies on facelets to set the attributes, so I have nothing implemented to handle expressions in the attributes.

             

            I'm still curious about why this is actually a problem. I've been working with JSF for quite a few years now, and I'm still bumping into issues like these, making me realise why newbies and managers have such a problem with the technology

             

            Anyway, I worked around this problem by using f:attribute tags on my component, and I use these in my validator instead of tag attributes.