【发布时间】: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