1 Reply Latest reply on Jun 20, 2008 1:55 PM by Mark LoSacco

    Any way to call HtmlTree.setAdviseNodeOpened() without using

    Mark LoSacco Newbie

      I am creating a rich tree dynamically from code.

      I need to be able to set an AdviseOpened and AdviseSelected callback for the tree.

      The apis HtmlTree.setAdviseOpened() and setAdviseSelected() both take MethodBinding's. However this has been deprecated...

      Is there a way to call these APIs using a MethodExpression?

      What is recommended way to use these APIs?

      Thanks,
      Mark

        • 1. Solution
          Mark LoSacco Newbie

          To solve this I created a Method Binding implementation:

          import javax.faces.el.MethodBinding;
          import javax.faces.context.FacesContext;
          import javax.el.MethodExpression;
          import javax.el.MethodInfo;
          
          public class MyMethodBinding extends MethodBinding implements java.io.Serializable
          {
           private static final long serialVersionUID = -3492518451005895022L;
           private MethodExpression expression;
          
           public MyMethodBinding(MethodExpression expr) {
           this.expression = expr;
           }
          
           public Class getType(FacesContext context) {
           MethodInfo info = expression.getMethodInfo(context.getELContext());
           return info.getReturnType();
           }
          
           public Object invoke(FacesContext context, Object[] params) {
           return this.expression.invoke(context.getELContext(), params);
           }
          
           public String getExpressionString() {
           return this.expression.getExpressionString();
           }
          }
          


          Then in the code to create the tree create a MethodExpression first, then use that expression to instantiate MyMethodBinding and pass that to HtmlTree.setAdviseNodeOpened().

           tree.setAdviseNodeOpened(new MyMethodBinding(expFactory.createMethodExpression(
           FacesContext.getCurrentInstance().getELContext(),
           "#{navigationAction.adviseNodeOpened}", Boolean.class,
           new Class[]{UITree.class})));
          


          Sorry for the post - but hopefully this will help someone else out in future.

          -Mark