4 Replies Latest reply on Feb 25, 2008 8:36 AM by Martin Verzilli

    Programmatically add a A4J:JSFunction with ActionParams

    Martin Verzilli Newbie

      Hi! I've already posted this question in the A4J users forum, but it seems it fits this forum also; so I try here.

      I'm trying to programmatically create a jsFunction and pass parameters to a bean. The call to the corresponding action in the bean works alright, but I couldn't find a way to get the params assigned to properties in it.

      I'll show you a simplified example of the code I'm using:

      First, I have a custom component, let's call it MyComponent. In the setProperties method of the corresponding MyComponentTag class I have the following code:

      HtmlAjaxFunction myFunction = new HtmlAjaxFunction();
      
      myFunction.setName("myFunction");
      myFunction.setAction(application.createMethodBinding("#{myBean.myFunctionAction}", null));
      
      HtmlActionParameter htmlActionParam = new HtmlActionParameter();
      htmlActionParam.setName("myParam");
      htmlActionParam.setAssignToBinding(application.createValueBinding("#{myBean.myParam}"));
      
      myFunction.getChildren().add(htmlActionParam);
      
      component.getChildren().add(myFunction);
      


      The "application" variable holds the current Application instance (taken from the current Faces context) .

      Then I have a bean class MyBean with a private member myParam (and its corresponding getters and setters) and a method for the action myFunctionAction.

      I put a breakpoint in the body of the myFunctionAction method, then I call myFunction from the Firebug js console, and the myFunctionAction method is efectively being called. The problem, as I previously said, is the myParam property is never written to.

      Can anybody see anything wrong with my code? Perhaps it's completely wrong...

      Thanks in advance for your help!

      Martin