form rerendering and A4J
jamathison Feb 25, 2008 7:37 PMHi All,
I have some a form that contains <a4j:commandButton> tags that reRender the form. After the first reRender, the commandButtons cease to work. I have created a simple page and backing bean that show the problem I'm having.
I'm using Facelets, Seam and EJB3
XHTML:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:s="http://jboss.com/products/seam/taglib" xmlns:h="http://java.sun.com/jsf/html" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:a4j="https://ajax4jsf.dev.java.net/ajax"> <head><title>Feedback Test</title></head> <body> <h:form id='formSend'> <s:div id='divFeedback'> <s:fragment rendered='#{not testAction.initialized and not testAction.sent}'> <p>Step 1: Hit Initialize</p> <a4j:commandButton id='cmdInit' action='#{testAction.init}' reRender='divFeedback' value='Initialize'/> </s:fragment> <s:fragment rendered='#{testAction.initialized}'> <p>Step 2: Hit Send</p> <a4j:commandButton id='cmdSend' action='#{testAction.send}' reRender='divFeedback' value='Send'/> </s:fragment> <s:fragment rendered='#{testAction.sent}'> <p>Step 3: Done</p> <p>If you can see this, then this page is working correctly.</p> <a4j:commandButton id='cmdClear' action='#{testAction.clear}' reRender='divFeedback' value='Start Over'/> </s:fragment> </s:div> </h:form> </body> </html>
Backing Bean:
package com.mc.test; import org.jboss.seam.annotations.Name; import org.jboss.seam.annotations.Logger; import org.jboss.seam.annotations.Scope; import org.jboss.seam.log.Log; import org.jboss.seam.ScopeType; @Name("testAction") @Scope(ScopeType.CONVERSATION) public class TestAction { @Logger Log log; private String state; public TestAction() { } public void init() { log.debug("Do init()"); this.state = "initialized"; } public void send() { log.debug("Do send()"); this.state = "sent"; } public void clear() { log.debug("Do clear()"); this.state = null; } public Boolean getInitialized() { return "initialized".equals(this.state);} public Boolean getSent() { return "sent".equals(this.state);} }
Upon clicking the Initialize button, the testAction.init action is invoked, and the form re-renders Step 2, as it should. However, then clicking Send does not invoke the testAction.send action.
I found that if I change the scope of the backing bean to Session, the form re-renders correctly, but that is not an option for our production site.
Any help would be greatly appreciated,
thanks,
Al