Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
860 views
in Technique[技术] by (71.8m points)

ajax - Address JSF component in ui:repeat

I'm trying to update an element within an UI-repeat, but unfortunately I still haven't discovered how to correctly address the outputPanel from within the dataTable. I am aware that this problem comes from the different naming containers, nevertheless, I hope there will be a solution.

<h:body>
    <h:form id="form">
        <ui:repeat var="_entry" value="#{test.entries}">
            <p:outputPanel id="counterPanel">
                <h:outputText value="#{test.counter}" />
            </p:outputPanel>

            <p:dataTable var="_p" id="paramTable" value="#{_entry.params}">
                <p:column headerText="Options">
                    <p:commandLink value="Update" update="counterPanel"  />
                </p:column>
            </p:dataTable>
        </ui:repeat>
    </h:form>
</h:body>

The code example above raises the following exception:

javax.servlet.ServletException: Cannot find component with identifier "counterPanel" in view.

Thx, Jakob

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Two ways:

  1. You need to give the <ui:repeat> a client ID so that you can refer it by the absolute client ID path:

    <h:form id="form">
        <ui:repeat id="entries" var="_entry" value="#{test.entries}">
            <p:outputPanel id="counterPanel">
                <h:outputText value="#{test.counter}" />
            </p:outputPanel>
    
            <p:dataTable var="_p" id="paramTable" value="#{_entry.params}">
                <p:column headerText="Options">
                    <p:commandLink value="Update" update=":form:entries:counterPanel" />
                </p:column>
            </p:dataTable>
        </ui:repeat>
    </h:form>
    
  2. Move the <h:form> to inside the outer loop so that you can use @form:

    <ui:repeat var="_entry" value="#{test.entries}">
        <h:form id="form">
            <p:outputPanel id="counterPanel">
                <h:outputText value="#{test.counter}" />
            </p:outputPanel>
    
            <p:dataTable var="_p" id="paramTable" value="#{_entry.params}">
                <p:column headerText="Options">
                    <p:commandLink value="Update" update="@form" />
                </p:column>
            </p:dataTable>
        </h:form>
    </ui:repeat>
    

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...