a4j:ajax "listener" not evaluating/invoking MethodExpression properly?
ultrapod Mar 15, 2011 3:58 PMI'm in the process of upgrading my application from Facelets/JSF 1.2/RichFaces 3.3.3 to JSF 2.0/RichFaces 4.0 and I'm having trouble transitioning from the a4j:support tag to the a4j:ajax tag. Specifically, I'm having difficulty using a ui:param to pass a MethodExpression to the "listener" property of the a4j:ajax tag. This is a technique that was working for for me with the old a4j:support tag, and my application uses this pattern extensively, so I'm really keen to find a solution!
Here's a simplified example of what I'm trying to do with the a4j:ajax tag which is *not* working right now.
test_outer.xhtml
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:a4j="http://richfaces.org/a4j" xmlns:rich="http://richfaces.org/rich"> <ui:composition> <html> <h:head> </h:head> <h:body> <h:form> <ui:include src="test_inner.xhtml"> <ui:param name="controller_bean" value="#{TestBean}"/> </ui:include> </h:form> </h:body> </html> </ui:composition> </html>
test_inner.xhtml
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:a4j="http://richfaces.org/a4j" xmlns:rich="http://richfaces.org/rich"> <ui:composition> <rich:extendedDataTable value = "#{controller_bean.list}" var = "rowvar" selectionMode="single"> <a4j:ajax event="selectionchange" listener="#{controller_bean.action}"/> <rich:column> <f:facet name="header"> <h:outputText value="Value" /> </f:facet> <h:outputText value="#{rowvar}"/> </rich:column> </rich:extendedDataTable> </ui:composition> </html>
TestBean.java
@ManagedBean(name="TestBean") @SessionScoped public class TestBean { private static Logger logger = Logger.getLogger(TestBean.class.getName()); public List<String> getList() { String[] num = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10"}; ArrayList<String> nums = new ArrayList<String>(Arrays.asList(num)); return nums; } public void action(AjaxBehaviorEvent event) { logger.info("action"); } }
With this code, when I select a row in the extendedDataTable, I get an error:
WARNING [javax.enterprise.resource.webcontainer.jsf.lifecycle] Target Unreachable, identifier 'controller_bean' resolved to null: javax.el.PropertyNotFoundException: Target Unreachable, identifier 'controller_bean' resolved to null ... ERROR [STDERR] javax.faces.FacesException: Target Unreachable, identifier 'controller_bean' resolved to null ... ERROR [STDERR] Caused by: javax.el.PropertyNotFoundException: Target Unreachable, identifier 'controller_bean' resolved to null
This error seems transparently bogus to me, because the table otherwise displays the values in the list.
What I had been doing (which was working great until now) was use the a4j:support tag:
<a4j:support event="onselectionchange" actionListener="#{controller_bean.action}"/>
In this case, the action method (with the proper ActionEvent signature, of course) would get invoked, no problem.
Help!