Igor
Igor

Reputation: 1464

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?

Upvotes: 0

Views: 264

Answers (2)

Dejell
Dejell

Reputation: 14337

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.

Upvotes: 6

Alexander Pogrebnyak
Alexander Pogrebnyak

Reputation: 45606

Looks like home.getInstance() is not thread safe.

You probably have bigger problems that need to be addressed here, but one band-aid solution would be to save the instance value before doing the layout here.

Put this before your code snippet

<c:set var="home_instance" value = "${home.instance}"/>

And replace home.instance with home_instance.

Upvotes: 0

Related Questions