1

我有一个由两种形式组成的简单页面。它们不能同时显示(一个切换另一个)。这是代码:

<h:body>

    <ui:composition template="/elements/templateWithMenu.xhtml">            
        <ui:define name="content">

            <p:dialog id="question1DialogId" widgetVar="question1Dialog" resizable="false" closable="false" visible="true">                             

                <h:panelGroup id="questionStep1Group">
                    <h:form id="questionStep1Form" rendered="#{newPoll2.displayQuestionStep1}">

                        <h:commandLink value="next" action="#{newPoll2.questionStep1Completed()}" class="btn" >
                            <f:ajax execute="@form" render=":questionStep2Form :questionStep1Group :questionStep2Group"/>
                        </h:commandLink>

                    </h:form>
                </h:panelGroup>

                <h:panelGroup id="questionStep2Group">
                    <h:form id="questionStep2Form"  rendered="#{newPoll2.displayQuestionStep2}">

                        <h:commandLink value="cancel" action="#{newPoll2.questionStep2Cancelled()}" class="btn" >
                            <f:ajax execute="@form" render=":questionStep1Form :questionStep1Group :questionStep2Group" />
                        </h:commandLink>

                    </h:form>
                </h:panelGroup>

            </p:dialog>

        </ui:define>
    </ui:composition>

</h:body>

questionStep1Completed()questionStep2Cancelled()只是切换渲染属性中使用的布尔值。

问题在于视图状态。首次加载页面时,单击“下一步”将起作用,并将替换为“取消”链接。但是当我单击“取消”链接时,需要单击两次才能将其替换为“下一个”链接。我可以看到第一次单击发出没有视图状态的请求,第二次(成功)发出请求。

我看到了这个问题和这个链接,正如你所看到的,我在渲染属性中添加了表单 ID,但它仍然不起作用。有任何想法吗?

谢谢

4

1 回答 1

2

您正在有条件地呈现表单本身,因此在准备 ajax 请求时,其他表单在 HTML DOM 树中实际上是不可用的。如果您将表单的内容包装在另一个中<h:panelGroup>并将rendered属性移动到那里,那么它应该可以工作。

于 2012-06-23T00:14:20.573 回答