3 Replies Latest reply on Feb 6, 2014 2:31 PM by bleathem

    UICommandLink inside HtmlColumn don´t call bean method.

    danilocps

      Hi all.

       

      I am experiencing a problem with the dynamic components UICommandLink inside the HtmlColumn component.

       

      I created a datatable:

      Application app = FacesContext.getCurrentInstance().getApplication();
      HtmlDataTable dataTable = (HtmlDataTable) app.createComponent(HtmlDataTable.COMPONENT_TYPE);
      dataTable.setValue(someDataModel);
      dataTable.setVar("item");
      
      HtmlColumn col = (HtmlColumn) app.createComponent(HtmlColumn.COMPONENT_TYPE);
      UIOutput out = (UIOutput) app.createComponent(UIOutput.COMPONENT_TYPE);
      out.setValue("col title");
      col.getFacets().put("header", out);
      
      UICommandLink link = (UICommandLink) app.createComponent(UICommandLink.COMPONENT_TYPE);
      link.setExecute("@this");
      link.setValue("click here");
      
      ExpressionFactory expf = FacesContext.getCurrentInstance().getApplication().getExpressionFactory();
      MethodExpression exp = expf.createMethodExpression(ctx.getELContext(), "#{myBean.actionLink}"
                      , null, new Class[] {});
      link.setActionExpression(exp);
      
      col.getChildren().add(link);
      dataTable.getChildren().add(col);
      

       

      The method actionLink in myBean is not called.

       

      But if I put the UICommandLink outside the dataTable works.  Or if I put the UICommandLink in (header of HtmlColumn):

      col.setHeader(link);
      

      Works fine.

       

      The problem is when the UICommandLink inside the HtmlColumn component (as children).

       

      To solve temporarily this problem, my commandLink call a jsFunction:

      UICommandLink link = (UICommandLink) app.createComponent(UICommandLink.COMPONENT_TYPE);
      link.setExecute("@none");
      link.setValue("click here");
      
      ExpressionFactory expf = FacesContext.getCurrentInstance().getApplication().getExpressionFactory();
      ValueExpression vexp = expf.createValueExpression(ctx.getELContext(), "jsCommandLinkTemp('#{item[0]}'); return false;", Object.class);
      link.setValueExpression("onclick",vexp);
      col.getChildren().add(link);
      

      the xhtml:

      <a4j:jsFunction name="jsCommandLinkTemp" action="#{myBean.actionLink}">
        <a4j:param name="param1" assignTo="#{myBean.idDataTable}"/>
      </a4j:jsFunction>
      

       

      The method actionLink is called and the attribute idDataTable receive the dataTable information, everything works.

       

      Did I do something wrong? I have to pass some attribute to UICommandLink? I don´t want to use JsFunction to call my method.

       

      Thanks (sorry about my english)