JSF Facelets ui:repeat tag breaks redisplaying of values in a form when validation failed

Submitted by Jochus on Thu, 20/09/2012 - 20:52 | Posted in: Java


I'm currently working on a project which uses the Mojarra 2.0.3 JSF reference implementation. I encounterd a really strange bug today ...
Imagine you have the following form (code entered in pseudocode, just to make it compact and clear):

<h:form>
    <div>
        <h:inputText id="field1" value="#{Bean.singleField.value}" required="true"/>
    </div>
    <div>
         <ui:repeat value="#{Bean.listOfFields}" var="field">
             <h:inputText value="#{field.value}"/>
         </ui:repeat>   
    </div>
    <h:commandButton value="Submit" type="submit" action="#{Bean.doAction} />
</h:form>

Scenario:
Now, when you don't provide a value in field1 (you do provide values in the other fields) and you submit the form, validation will fail (because of the required attribute).

The problem:
When the form rerenders, all values in the input fields inside the ui:repeat tag are gone.

The solution
After some research, we found out we stumbled into the following bug: http://java.net/jira/browse/JAVASERVERFACES-1807. So we should upgrade our JSF implementation (which isn't an option for the moment). Luckily, we are using Richfaces in our project so we could replace the ui:repeat tag by the A4J equivalent: aj4:repeat.

Add new comment

The content of this field is kept private and will not be shown publicly.

Full HTML

  • Lines and paragraphs break automatically.
  • You can caption images (data-caption="Text"), but also videos, blockquotes, and so on.
  • Web page addresses and email addresses turn into links automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <bash>, <cpp>, <css>, <html5>, <java>, <javascript>, <php>, <sql>, <xml>. The supported tag styles are: <foo>, [foo].
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.