Since I asked my last question (which has not yet been answered), I continued to search for a solution, and finally I found this section , which, I think, can help in achieving what I want.
So, I tried this solution (which in itself is a workaround), but it still does not work for me.
Here is the code, this is just a test for this problem:
index.xhtml:
<?xml version="1.0" encoding="ISO-8859-1" ?> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:p="http://primefaces.org/ui" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:c="http://java.sun.com/jsp/jstl/core"> <h:head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> <title>dyn add comps test </title> </h:head> <body> <h:form id="form1"> <h:commandLink value="cliick me"> <f:ajax event="click" listener="#{myBean.firstcmdLinkListenerHandler}"/> </h:commandLink> </h:form> </body> </html>
Managed by Bean: MyBean.java
package mybeans; import javax.el.ExpressionFactory; import javax.el.MethodExpression; import javax.faces.application.Application; import javax.faces.bean.ManagedBean; import javax.faces.bean.SessionScoped; import javax.faces.component.UIComponent; import javax.faces.component.html.HtmlCommandLink; import javax.faces.context.FacesContext; import javax.faces.event.AjaxBehaviorEvent; import javax.faces.event.BehaviorEvent; import org.primefaces.component.behavior.ajax.AjaxBehaviorListenerImpl; import org.primefaces.context.RequestContext; @ManagedBean @SessionScoped public class MyBean { public void handleClose(AjaxBehaviorEvent abe){ System.out.println("!!!-->>>>> the Ajax Behaviour Works !!!!! "); } public void reLoadCityList( BehaviorEvent event ){ System.out.println("!!!-->>>>> the reLoadCityList method Works !!!!! "); } public void firstcmdLinkListenerHandler(AjaxBehaviorEvent abe){ System.out.println("firstcmdLinkListenerHandleris running ! "); FacesContext fc = FacesContext.getCurrentInstance(); Application application = fc.getApplication(); ExpressionFactory ef = fc.getApplication().getExpressionFactory(); UIComponent form1 = fc.getViewRoot().findComponent("form1"); if(form1!=null){
MyAjaxBehavior.java is used as a workaround in the Surfaces forum article:
package mybeans; import java.util.HashMap; import javax.el.ELContext; import javax.el.MethodExpression; import javax.faces.component.UIComponentBase; import javax.faces.context.FacesContext; import javax.faces.event.AbortProcessingException; import javax.faces.event.BehaviorEvent; import org.primefaces.component.behavior.ajax.AjaxBehavior; public class MyAjaxBehavior extends AjaxBehavior { @Override public Object saveState(FacesContext context) { HashMap<String, Object> map; map = new HashMap<String, Object>(); map.put("update", getUpdate()); map.put("process", getProcess()); map.put("oncomplete", getOncomplete()); map.put("onerror", getOnerror()); map.put("onsuccess", getOnsuccess()); map.put("onstart", getOnstart()); map.put("listener", getListener()); if (initialStateMarked()) return null; return UIComponentBase.saveAttachedState(context, map); } @SuppressWarnings("unchecked") @Override public void restoreState(FacesContext context, Object state) { if (state != null) { HashMap<String, Object> map; map = (HashMap<String, Object>) UIComponentBase .restoreAttachedState(context, state); setUpdate((String) map.get("update")); setProcess((String) map.get("process")); setOncomplete((String) map.get("oncomplete")); setOnerror((String) map.get("onerror")); setOnsuccess((String) map.get("onsuccess")); setOnstart((String) map.get("onstart")); setListener((MethodExpression) map.get("listener")); } } @Override public void broadcast(BehaviorEvent event) throws AbortProcessingException { ELContext eLContext = FacesContext.getCurrentInstance().getELContext();