Search code examples
javajsfrichfaces

How to work with c:foreach and other fields after it?


My problem is that in my home page, I get the variable capacidade perfectly. Then I have that c:forEach there and the other field named "nome". When I try to persist, then I get the capacidade field filled, but the "nome" attribute comes null. I saw that if I push him before the c:forEach, then it works. But I need to keep him after c:forEach fields.

<s:decorate template="layout/form.xhtml">
            <ui:define name="label">capacidade:</ui:define>
            <h:inputText size="50" value="#{home.instance.capacidade}" maxlength="100" required="true" />
        </s:decorate>

        <a4j:outputPanel id="camposPresenca">
            <c:forEach items="#{home.presencas}" var="presenca" varStatus="loop">
                <s:decorate template="layout/form.xhtml">
                    <ui:define name="label">Presença #{loop.index + 1}</ui:define>
                    <rich:calendar enableManualInput="true" value="#{presenca.dataPresenca}" datePattern="dd/MM/yyyy" oninputblur="validarData(this);" required="true"/>
                    <h:inputText size="100" value="#{presenca.horarioPresenca}" maxlength="250" />
                </s:decorate>
            </c:forEach>
        </a4j:outputPanel>

        <s:decorate template="layout/form.xhtml">
            <ui:define name="label">Nome:</ui:define>
            <h:inputText size="50" value="#{home.instance.nome}" maxlength="100" required="true" />

someone knows how to solve that problem?


Solution

  • Use <ui:repeat> instead of <c:forEach> the later is not a component and are not part of the tree component after the page is built.

    Read more in this article.

    In General: JSTL elements break ViewScope beans.