如果将第一个按钮更改为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>
答案 0 :(得分:0)
我发现了问题,我有两个表单标签,每个按钮一个,这就是问题所在。我将整个代码包装成一种形式,现在可以按需运行了。
从这里获得解决方案: 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>