0 Replies Latest reply on Feb 22, 2008 9:33 AM by martinverzilli

    Programmatically create a jsFunction and pass parameters to

    martinverzilli

      Hi! 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 advanced for your help!

      Martin