a4j:commandButton and page refresh problem
howhigh Feb 23, 2012 10:38 AMHi,
I have a page which has a part that can change when an user click on a a4j:commandButton.
<div> <a4j:outputPanel id="panelItems" layout="block"> <rich:panel rendered="#{fhIndBean.displayPanelItems}"> <h:form> <rich:tabPanel switchType="ajax" activeItem="#{fhIndBean.activeTab}"> ... </rich:tabPanel> </h:form> <h:form> <a4j:commandButton styleClass="no-decor" value="#{msg.addMessage}" render="panelListCh, panelItems" actionListener="#{fhIndBean.displayListInvoiceLines}"> </a4j:commandButton> </h:form> </rich:panel> </a4j:outputPanel> <a4j:outputPanel id="panelListCh" layout="block"> <rich:panel rendered="#{fhIndBean.displayPanelListCh}"> <ui:include src="./fhIndDetails/listInvoiceLines.xhtml" /> <h:form> <a4j:commandButton styleClass="no-decor" value="#{msg.cancel}" render="panelItems, panelListCh" actionListener="#{fhIndBean.cancelDisplayListInvoiceLines}"> </a4j:commandButton> </h:form> </rich:panel> </a4j:outputPanel> </div>
In my bean, I've two booleans which indicate wheter or not a part should be rendered and two listeners:
private boolean displayPanelItems = true; private boolean displayPanelListCh = false; ... public void displayListInvoiceLines() { LOGGER.error("DISPLAY"); displayPanelItems = false; displayPanelListCh = true; ... } public void cancelDisplayListInvoiceLines() { LOGGER.error("CANCEL"); displayPanelItems = true; displayPanelListCh = false; ... }
By default, panelItems is rendered.
When I click on the commandButton in this panel, it's hidden and the panel panelListCh is rendered. Till now everything works as expected:
16:24:56.279 [http-bio-8280-exec-5] ERROR LifeCycleListener - START PHASE RESTORE_VIEW 1 16:24:56.375 [http-bio-8280-exec-5] ERROR LifeCycleListener - END PHASE RESTORE_VIEW 1 16:24:56.375 [http-bio-8280-exec-5] ERROR LifeCycleListener - START PHASE APPLY_REQUEST_VALUES 2 16:24:56.379 [http-bio-8280-exec-5] ERROR LifeCycleListener - END PHASE APPLY_REQUEST_VALUES 2 16:24:56.379 [http-bio-8280-exec-5] ERROR LifeCycleListener - START PHASE PROCESS_VALIDATIONS 3 16:24:56.381 [http-bio-8280-exec-5] ERROR LifeCycleListener - END PHASE PROCESS_VALIDATIONS 3 16:24:56.381 [http-bio-8280-exec-5] ERROR LifeCycleListener - START PHASE UPDATE_MODEL_VALUES 4 16:24:56.383 [http-bio-8280-exec-5] ERROR LifeCycleListener - END PHASE UPDATE_MODEL_VALUES 4 16:24:56.383 [http-bio-8280-exec-5] ERROR LifeCycleListener - START PHASE INVOKE_APPLICATION 5 16:24:56.383 [http-bio-8280-exec-5] ERROR FhIndBean - DISPLAY 16:24:56.383 [http-bio-8280-exec-5] ERROR LifeCycleListener - END PHASE INVOKE_APPLICATION 5 16:24:56.384 [http-bio-8280-exec-5] ERROR LifeCycleListener - START PHASE RENDER_RESPONSE 6 ...
and panelListCh is well rendered.
And now if I click on the commandbutton to display panelItems again I got some serious troubles:
16:26:51.660 [http-bio-8280-exec-3] ERROR LifeCycleListener - START PHASE RESTORE_VIEW 1 16:26:51.663 [http-bio-8280-exec-3] ERROR LifeCycleListener - END PHASE RESTORE_VIEW 1 16:26:51.663 [http-bio-8280-exec-3] ERROR LifeCycleListener - START PHASE RENDER_RESPONSE 6 16:26:51.732 [http-bio-8280-exec-3] ERROR FhIndBean - POSTCONSTRUCT ...
The bean is rebuilt and the actionListener which normally should log the word CANCEL is not called.
The fhIndBean is in ViewScope so normally, the problem with conditional rendering should not appeared (https://community.jboss.org/wiki/CommonAjaxRequestsProblems#conditionalRendering).
If I put fhIndBean in SessionScope the problem is that it doesn't render the good panel because the actionListener isnt called (so booleans aren't changed) but the bean isnt rebuilt.
If I change a4j:commandButton to h:commandButton everything is good except the fact that the page is refreshed (no ajax).
What am I doing wrong?
Thanks in advance!