data access problem in jsf
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.
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>
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?
精彩评论