【问题标题】:jsf a4j:commandButton reRender doesn't workjsf a4j:commandButton reRender 不起作用
【发布时间】:2019-12-27 11:22:01
【问题描述】:

如果我将第一个按钮更改为 h:commandButton,我的 jsf 页面可以正常工作。但是,这会刷新提交时的整个页面,因此我的要求是将两者都保留为支持 ajax 的按钮。 我的支持 bean 具有所有必需的方法。单击第二个按钮时,以下代码不会打印出选择。日志打印“null”作为选择。我究竟做错了什么?

<h:form>
<a4j:commandButton action="#{Bean.getAllReps}" value="Get REPS" reRender="showReps" />
</h:form>
<h:panelGrid columns="1" id="showReps">
    <h:panelGrid rendered="#{Bean.actionComplete eq 'fail'}" width="100%" columns="2">
        <h:outputText value="Could not get Details" style="color: red; font-size:3mm;" />
    </h:panelGrid>
            <h:panelGrid rendered="#{Bean.actionComplete eq 'success'}">
                <h:panelGrid>
                    <h:outputText>
                        <rich:panel>
                            <h:form>
                                <h:panelGrid>
                                    <rich:pickList value="#{Bean.slctdRep}" style="text-align: left;">
                                        <f:selectItems value="#{Bean.allReps}" />
                                    </rich:pickList>
                                </h:panelGrid>

                                <a4j:commandButton value="Show Selection" reRender="content" type="submit"></a4j:commandButton> //This button doesn't perform partial refresh on element with id "content"

                            </h:form>
                        </rich:panel>
                        <rich:panel>
                            <h:panelGroup id="content" layout="block">
                                <h:outputText value="Selected Reps : "></h:outputText>
                                <h:outputText value="#{Bean.selectedRepsInString}"></h:outputText>
                            </h:panelGroup>
                        </rich:panel>

                    </h:outputText>
                </h:panelGrid>
            </h:panelGrid>
</h:panelGrid>

【问题讨论】:

  • 所以这个动作被调用了?
  • 是的,第一个按钮被调用,但是,如果我将第二个按钮也设为 a4j:commandButton,那么第二个 commandButton 将停止工作。它没有呈现 id='content' 的面板
  • 但它正在重新渲染h:outputText 内的另一个rich:panel(这是一个奇怪且应避免的构造!!!
  • 你建议我应该怎么做才能让两个按钮都工作?
  • 并创建一个minimal reproducible example。缺少代码...我怀疑您在stackoverflow.com/questions/2118656/… 中遇到了#2

标签: jsf jsf-1.2


【解决方案1】:

我发现了问题,我有两个表单标签,每个按钮一个,这是导致问题的原因。我将整个代码包装在一种形式中,它现在可以按需要工作。

从这里得到解决方案: commandButton/commandLink/ajax action/listener method not invoked or input value not set/updated

更新代码:

<a4j:form>
    <a4j:commandButton action="#{Bean.getAllReps}" value="Get REPS" reRender="showReps" type="submit" />
    <h:panelGrid columns="1" id="showReps">
        <rich:panel>
            <h:panelGrid>
                <rich:pickList sourceListWidth="200" targetListWidth="200" value="#{Bean.slctdRep}">
                    <f:selectItems value="#{Bean.allReps}" />
                </rich:pickList>
            </h:panelGrid>

            <a4j:commandButton value="Show Selection" reRender="content" type="submit" action="#{Bean.getSelectedReps}" />
        </rich:panel>

        <rich:panel>
            <h:panelGroup layout="block" id="content">
                <h:outputText value="#{Bean.selectedReps}"></h:outputText>
            </h:panelGroup>
        </rich:panel>

    </h:panelGrid>
</a4j:form>

【讨论】:

    猜你喜欢
    • 2012-04-12
    • 2013-04-07
    • 2011-01-03
    • 2013-11-08
    • 1970-01-01
    • 2014-06-16
    • 1970-01-01
    • 2012-07-25
    相关资源
    最近更新 更多