2 Replies Latest reply on Aug 1, 2007 12:38 AM by Raymond Eperen

    Binding HtmlCommandLink to backing bean method programmatica

    Raymond Eperen Newbie

      I am creating a commandLink programmatically. I have everything working except to bind the link to a method in the backing bean. I don't see anything except a deprecated setAction() method on the class. How do I do this? Here's what I have so far:

      validateLink = new HtmlCommandLink();
       validateLink.setId("validateLink" + dataset.getId());
       validateLink.setRendered(true);
       validateLink.setImmediate(true);
       validateLink.setTitle("Begin the Validation Process for this Dataset");
       validateLink.setValue("Validate Dataset");
      


      Thanks,
      Ray

        • 1. Re: Binding HtmlCommandLink to backing bean method programma
          Tiago Newbie

          Hi there,

          maybe you solved it already, but here it goes.

          Try the addActionListener.. I think it works the same way AWT-Listeners.

          import javax.faces.event.ActionEvent;
          import javax.faces.event.ActionListener;


          ...
          validateLink.addActionListener(new ActionListener() {
          public void processAction(ActionEvent evt) {
          // do something
          }
          });


          • 2. Re: Binding HtmlCommandLink to backing bean method programma
            Raymond Eperen Newbie

            Thanks for the reply. I ended up creating the following utility method, which works fine:

             public static HtmlCommandLink buildCommandLink(final String pId, final String pExpression, final String pTitle,
             final String pValue, final boolean pImmediate, final boolean pRendered)
             {
             ExpressionFactory factory = ExpressionFactory.newInstance();
             MethodExpression expression = factory.createMethodExpression(FacesContext.getCurrentInstance().getELContext(),
             "#{" + pExpression + "}", String.class, new Class[0]);
            
             HtmlCommandLink link = new HtmlCommandLink();
             link.setId(pId);
             link.setRendered(pRendered);
             link.setImmediate(pImmediate);
             link.setTitle(pTitle);
             link.setValue(pValue);
             link.setActionExpression(expression);
            
             return link;
             }