0

I have the following class-files:

class RowData {
...
  ArrayList<String> valueMap;
...
}

class Bean {
...
  public List<RowData> getData() {
  ...
  }
}

jsf code snippet:

...
<h:form>
  <rich:dataTable id="overviewTable" value="#{bean.getData()}" var="row">

    <c:forEach items="#{row.valueMap}" var="r">

      <rich:column>
        <h:outputText value="#{r}" />
      </rich:column>
    </c:forEach>
  </rich:dataTable> 
</h:form>
...

Unfortunately, the table doesn't appear. What's wrong? The page doesn't show an error or something, the table is just not there (in this version I skipped all the getter and setter...). When I want to access other data from the bean, it works, so the whole setup should be ok.

  • A very similar quesiton has been asked before: http://stackoverflow.com/questions/7083444/using-foreach-into-jsf-xhtml – BalusC Aug 18 '11 at 15:29

2 Answers2

2

you should not write the "get" and the "()" in "getData()", also, I dont think you need the "foreach" in a datatable

look at this example from http://richfaces-showcase.appspot.com/richfaces/component-sample.jsf?demo=dataTable&sample=tableStyling&skin=blueSky

<rich:dataTable value="#{carsBean.allInventoryItems}" var="car"
        id="table" rows="20" rowClasses="odd-row, even-row"
        styleClass="stable">
        <rich:column accept="#{carsFiteringBean.acceptVendor}">
            <f:facet name="header">
                <h:outputText value="Vendor " />
            </f:facet>
            <h:outputText value="#{car.vendor}" />
        </rich:column>
        <rich:column>
            <f:facet name="header">
                <h:outputText value="Model" />
            </f:facet>
            <h:outputText value="#{car.model}" />
        </rich:column>
        <rich:column>
            <f:facet name="header">
                <h:outputText value="Price" />
            </f:facet>
            <h:outputText value="#{car.price}" />
        </rich:column>
        <rich:column filter="#{carsFilteringBean.mileageFilterImpl}">
            <f:facet name="header">
                <h:outputText value="Mileage" />
            </f:facet>
            <h:outputText value="#{car.mileage}" />
        </rich:column>
        <rich:column>
            <f:facet name="header">
                <h:outputText value="VIN " />
            </f:facet>
            <h:outputText value="#{car.vin}" />
        </rich:column>
    </rich:dataTable>
</h:form>
dov.amir
  • 11,489
  • 7
  • 45
  • 51
  • thanks for your answer. but I'm not sure if I got it right. As you can see in the above code, "getData()" is a method which returns a List of elements. There is no attribute in the bean called data or something else. I removed the brackets but still not working. – inGoogleITrust Aug 18 '11 at 15:23
  • @inGoogleITrust: EL does not call attributes .. It calls getter/setter methods. I.e. `#{bean.data}` does under the covers exactly the same as `bean.getData()`! Go back to your school books. See also http://stackoverflow.com/tags/el/info Calling arbitrary methods only works since EL 2.2. So I think you was misled by that. Your concrete problem boils down to using `` inside `` anyway. – BalusC Aug 18 '11 at 15:26
0

Use value="#{bean.data}" instead. Remember, you're using E.L and it is assumed that you're referencing a java bean property named data through the getter method getData(). The data property might not exists but the method named should definitely be named like this.

Also, in order to use the items="#{row.valueMap}" idiom, you must have a getValueMap() method present in your bean class.

Do you get the idea?

Jose Diaz
  • 5,353
  • 1
  • 31
  • 29
  • yeah that's interesting now, because the following works pretty well (for which there is also no property in the bean) where getRecordClassesList() is a method in the Bean class. The only difference is that in this case, the method is called in the foreach and not in the – inGoogleITrust Aug 18 '11 at 15:29