2 Replies Latest reply on Jun 18, 2010 3:37 AM by Paulo Pinto

    How to write to attributes with the CDK?

    Paulo Pinto Novice

      Hi,

       

      on the component I am currently writting with the CDK, I do have the need to write to some attributes, similar to the standard JSF attribute var.

       

      If I would be coding the component without the CDK, I would write something like this on my tag handler (Facelets):

       

      {code:java}
      faceletContext.setAttribute (var.getValue(faceletContext), value)
      {code}

       

      Is this done with the variable mechanism in the CDK?

       

      Thanks

        • 1. Re: How to write to attributes with the CDK?
          Bernard Labno Master

          In renderer for exemple you can do:

          ValueExpression valueExpression = getFacesContext().getApplication().getExpressionFactory().createValueExpression(getFacesContext().getELContext(), "#{" + getVar() + "}", Object.class);

          List<Map<String, Object>> data = new ArrayList<Map<String, Object>>();
          for (int i = 0; i < dataModel.getRowCount(); i++) {
               dataModel.setRowIndex(i);
               valueExpression.setValue(elContext, dataModel.getRowData());

          //...do something, i.e. render children that have bindings to "var" value

          }

          • 2. Re: How to write to attributes with the CDK?
            Paulo Pinto Novice

            If I understood it correctly, your suggestion only works if you are giving the output variable to child tags, which is not our use case.

             

            I want to be able to do the following:

             

            {code:xml}

            <mytag attribute="value" outputVar1="my_var1" outputVar2="my_var2"/>

            <h:outputText value="#{my_var1}"/>

            <h:outputText value="#{my_var2}"/>

            {code}

             

             

            I know how to do this with the Facelets API directly, but the CDK generates the Facelets tag handler, so the question is how to handle attribute creation with the CDK?