1 Reply Latest reply on Dec 29, 2008 7:01 AM by Andrei Markavtsov

    rich:columns & dynamic components binding

    Alexey Kochkin Newbie

      Hi,

      I changed code from examples:

      <rich:dataTable value="#{dataTableScrollerBean.model}" var="model" width="750">
      <f:facet name="header">
      <h:outputText value="Cars Available"/>
      </f:facet>
      <rich:columns value="#{dataTableScrollerBean.columns}" var="columns"
      index="ind" sortBy="#{model[ind].price}">
      <f:facet name="header">
      <h:outputText value="#{columns.header}"/>
      </f:facet>
      <h:outputText binding="#{dataTableScrollerBean.text}"/>
      <h:outputText value="#{model[ind].mileage} miles "/>
      <h:outputText value="#{model[ind].price}$"
      style="font-style:italic;"/>
      </rich:columns>
      </rich:dataTable>


      in backing bean method was add

      private HtmlOutputText retVal;

      public HtmlOutputText getText()
      {
      if (retVal == null)
      {
      retVal = (HtmlOutputText) FacesContext
      .getCurrentInstance()
      .getApplication()
      .createComponent(HtmlOutputText.COMPONENT_TYPE);
      FacesContext ctx = FacesContext.getCurrentInstance();
      ELContext elCtx = ctx.getELContext();
      ExpressionFactory ef = ctx.getApplication().getExpressionFactory();
      ValueExpression ve = ef.createValueExpression(elCtx, "#{model[ind].model}", String.class);
      retVal.setValueExpression("value", ve);
      }
      return retVal;
      }

      but binding doesn't work. OutputText with binding doesn't visible. What is wrong? This is a bag?

        • 1. Re: rich:columns & dynamic components binding
          Andrei Markavtsov Apprentice

          Hi,

          The problem is that you use outputText bound on the same bean variable.
          I detected that outputText displays only for the last column in this case.

          So, don't use the same variable. Create the new htmlOutput instance for each column:

          public HtmlOutputText getText() {
           HtmlOutputText retVal = null;
           if (retVal == null) {
           retVal = (HtmlOutputText) FacesContext.getCurrentInstance()
           .getApplication().createComponent(
           HtmlOutputText.COMPONENT_TYPE);
           FacesContext ctx = FacesContext.getCurrentInstance();
           ELContext elCtx = ctx.getELContext();
           ExpressionFactory ef = ctx.getApplication().getExpressionFactory();
           ValueExpression ve = ef.createValueExpression(elCtx,
           "#{model[ind].model}", String.class);
           retVal.setValueExpression("value", ve);
           }
           return retVal;
           }


          If you have not to create new HtmlOutputText variable you can use expression for outputText that references to bean static variable.