a4j:ajax not working with conditionally rendered h:selectOneMenu
josh68 Jan 20, 2012 6:55 PMHello. I'm having a problem with an application we're testing on (an admittedly unsupported configuration of) RF4.1 with JSF2.1 (servlet API is only 2.5). We're trying to port from a stack running JSF 1.2 and RF 3.3.1. We have our pages rendering correctly, and much is working, but this one issue has us stumped. This page was fully working on our old stack, using a4j:support.
We have a couple of cascading drop-downs using h:selectOneMenu, each with a4j:ajax support. The first drop-down sets a bean property and successfully renders the second drop-down, but the second drop-down is then supposed to set further bean properties and render other componenets on the page, and that's failing.
We added a dummy listener on the bean and it is successfully called by the first drop-down, but not the second. If we remove the conditional rendering around the second drop-down, it also calls the listener. We're stumped as to why the second drop-down doesn't even fire the listener when it's contained within a conditionally rendered block. Side-note: Firebug shows that the a4j:ajax js IS fired on use of the second drop-down, even though the listener isn't called.
Here's some code. The first two blocks are the drop-downs and the following blocks are what the second-dropdown is supposed to render. Again, the real issue is that the second drop-down seems to do nothing unless it is rendered on page load.
{code}
<ol>
<li id="payBillMethodSelect">
<h:outputLabel id="payBillSelectPaymentMethodLabel" forceId="true"
value="#{bundle.payBillSelectPaymentMethod}" />
<h:selectOneMenu id="payBillSelectPaymentMethod" value="#{paymentManagedBean.selectedPaymentAccount}" required="true" forceId="true">
<a4j:ajax event="change" render="paymentMethodsPanel" listener="#{paymentManagedBean.generalPurposeTestListener}" />
<f:selectItems value="#{paymentManagedBean.accountNickNames}" />
</h:selectOneMenu>
</li>
</ol>
<a4j:outputPanel id="paymentMethodsPanel"
layout="block">
<h:panelGroup rendered="#{paymentManagedBean.renderAddPayment}">
<ol>
<li>
<h:outputLabel id="payBillSelectPaymentTypeLabel"
value="SELECT PAYMENT TYPE" forceId="true" />
<h:selectOneMenu id="payBillSelectPaymentAccountType" value="#{paymentManagedBean.selectedPaymentAccountType}" required="true" forceId="true">
<a4j:ajax event="change" render="paymentTypesPanel securityCodePanel" listener="#{paymentManagedBean.generalPurposeTestListener}" />
<f:selectItems value="#{paymentManagedBean.paymentAccountTypes}" />
</h:selectOneMenu>
</li>
</ol>
</h:panelGroup>
</a4j:outputPanel>
<a4j:outputPanel id="securityCodePanel"
layout="block" forceId="true">
<h:panelGroup rendered="#{paymentManagedBean.renderSecurityCode}">
<ol>
<li>
<h:outputLabel for="payBillInputSecurityCode"
value="Security Code/CVV" />
<h:inputText
id="payBillInputSecurityCode" forceId="true"
value="#{paymentManagedBean.securityCode}" required="true" />
</li>
</ol>
</h:panelGroup>
</a4j:outputPanel>
<a4j:outputPanel id="paymentTypesPanel"
layout="block" styleClass="clear" forceId="true">
<h:panelGroup rendered="#{paymentManagedBean.renderCheckingTabContent || paymentManagedBean.renderSavingsTabContent}">
<div class="cssbox">
<ui:include id="paymentCheckingSavingsContent"
src="/pages/content/paymentTabCheckingSavingsContent.xhtml" />
</div>
</h:panelGroup>
<h:panelGroup rendered="#{paymentManagedBean.renderCreditTabContent}" id="paymentCredit">
<div class="cssbox">
<ui:include id="paymentCreditContent"
src="/pages/content/paymentTabCreditContent.xhtml" />
</div>
</h:panelGroup>
<h:panelGroup rendered="#{paymentManagedBean.renderDebitTabContent}" id="paymentDebit">
<div class="cssbox">
<ui:include id="paymentDebitContent"
src="/pages/content/paymentTabDebitContent.xhtml" />
</div>
</h:panelGroup>
</a4j:outputPanel>
{code}
I'm leaving any bean code off since I think it's irrelevant, but will post more if needed. Thanks in advance.