1 Reply Latest reply on Jun 23, 2011 5:28 AM by eunnini

    How to add a4j:ajax onblur programmatically in richfaces 4

    eunnini

      Hello,

       

      I'm moving  my application from rich3.3.3 to rich4. But, I have a lot programmatically created components. I read post http://209.132.182.49/thread/155679 and saw how to create AjaxBehavior, but I don't know how to implement onblur

      action for HtmlInputText. Could you give me some idea

       

      Thanks

        • 1. Re: How to add a4j:ajax onblur programmatically in richfaces 4
          eunnini

          Hello,

           

          I've found a solution

           

          public HtmlInputText createAjaxInput() {

            HtmlInputText input = (HtmlInputText) FacesContext.getCurrentInstance().getApplication().createComponent(HtmlInputText.COMPONENT_TYPE);    

            AjaxBehavior ajaxBehavior = (AjaxBehavior) FacesContext.getCurrentInstance().getApplication().createBehavior(AjaxBehavior.BEHAVIOR_ID);  

            MethodExpression listener = FacesContext.getCurrentInstance().getApplication().getExpressionFactory()

            .createMethodExpression(FacesContext.getCurrentInstance().getELContext(), "#{helloBean.inputAction}", null, new Class[] { BehaviorEvent.class });

            ajaxBehavior.addAjaxBehaviorListener(new MethodExpressionAjaxBehaviorListener(listener)); input.addClientBehavior("keyup", ajaxBehavior);

            input.addClientBehavior("blur", ajaxBehavior);

            return input;

          }

           

           

           

          Regards