0 Replies Latest reply on Jul 17, 2009 10:21 AM by prode

    ActionParam , JSFunction Issue

      Hi All,

      Let me explain what I am tryig to do


      If I include jsFunction as below in xhtml, it’s calling actionParam’s assignTo binding very well.

      <h:form id="appletform">
       <a4j:jsFunction name="appletShowObject" actionListener="#{appletBean.dispatchEvent}" ajaxSingle="true" immediate="true">
       <a4j:actionparam name="param1" assignTo="#{appletBean.objectId}"/>
       </a4j:jsFunction>
       </h:form>


      But, if I added the similar thing inside smApplet’s endcodeBegin() programaticaly, the actionparam’s assignTo binding never get called.
      Hecne I can not pass a parameters from applet to JSF Bean.

      encodeBegin()

      /** Adds A4j:jsFunction to call event handlers on widget */
       private void addJSFunction(FacesContext context) {
       if(!isJSFunctionPresent()) {
       //HtmlAjaxFunction a4jFunction = new HtmlAjaxFunction();
       HtmlAjaxFunction a4jFunction = (HtmlAjaxFunction)context.getApplication().createComponent(HtmlAjaxFunction.COMPONENT_TYPE);
       a4jFunction.setName("appletShowObject");
       a4jFunction.setId(context.getViewRoot().createUniqueId());
       a4jFunction.setAjaxSingle(true);
       a4jFunction.setImmediate(true);
       Class[] params = {javax.faces.event.ActionEvent.class};
       String actionExpressionn = "#{appletBean.dispatchEvent}";
       a4jFunction.addActionListener(new MethodExpressionActionListener(
       FacesUtils.createMethodExpression(actionExpressionn, null,
       params)));
       addA4jParams(context, a4jFunction, "param1", "#{appletBean.objectId}",String.class);
      
       this.getChildren().add(a4jFunction);
       }
       }


      private void addA4jParams(FacesContext context, HtmlAjaxFunction a4jFunction,String paramName, String Expression,Class<?> expectedType) {
       HtmlActionParameter a4jParam = (HtmlActionParameter)context.getApplication().createComponent(HtmlActionParameter.COMPONENT_TYPE);
       a4jParam.setName(paramName);
       a4jParam.setId(context.getViewRoot().createUniqueId());
       ValueExpression valExpr = context.getApplication()
       .getExpressionFactory()
       .createValueExpression(context.getELContext(),Expression,expectedType);
      
       //a4jParam.setAssignToBinding(valExpr);
       a4jParam.setValueExpression("assignToBinding", valExpr);
       Class[] params = {javax.faces.event.ActionEvent.class};
       String actionExpressionn = "#{appletBean.setParamValue}";
       a4jParam.setActionListener(
       FacesUtils.createMethodExpression(actionExpressionn, null,
       params));
      
       a4jFunction.getChildren().add(a4jParam);
       }


      Your any help is highly appreciated.

      Thanks in Advance!!!!!