Reputation: 660
I'm trying to show a empty datatable with 10 rows on the page load, when i try using the below code, it does not show any rows.
<h:dataTable id="d" value="" bgcolor="#9AC8E6" border="10" cellpadding="5" cellspacing="3" rows="10" width="100%" dir="LTR" frame="hsides" rules="all" >
<h:column>
<f:facet name="header">
<h:outputText style=""value="Student Number" />
</f:facet>
<h:inputText value="#{10}" > </h:inputText>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText style=""value="Student Name" />
</f:facet>
<h:inputText value="" > </h:inputText>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText style=""value="Standard" />
</f:facet>
<h:inputText value="" > </h:inputText>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText style=""value="Marks" />
</f:facet>
<h:inputText value="" > </h:inputText>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText style=""value="Percentage" />
</f:facet>
<h:inputText value="" > </h:inputText>
</h:column>
<h:column>
</h:dataTable>
Need help to display a datatable with blank columns and rows
According to the given solution I tried this way but could not resolve the problem
<h:dataTable id="d" value="#{inquiryBean.blankList}" var="emptyBean" bgcolor="#9AC8E6" border="10" cellpadding="5" cellspacing="3" rows="10" width="100%" dir="LTR" frame="hsides" rules="all" >
<h:column>
<f:facet name="header">
<h:outputText style=""value="Item Number" />
</f:facet>
<h:inputText value="#{emptyBean.itemNumber}" > </h:inputText>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText style=""value="Material" />
</f:facet>
<h:inputText value="#{emptyBean.material}" > </h:inputText>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText style=""value="Description" />
</f:facet>
<h:inputText value="#{emptyBean.description}" > </h:inputText>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText style=""value="Unit" />
</f:facet>
<h:inputText value="#{emptyBean.unit}" > </h:inputText>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText style=""value="Quantity" />
</f:facet>
<h:inputText value="#{emptyBean.quantity}" > </h:inputText>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText style=""value="Delivery Date" />
</f:facet>
<h:inputText value="#{emptyBean.deliveryDate}" > </h:inputText>
</h:column>
</h:dataTable>
## Bean Class ##
//getters and setters
List blankList = new ArrayList();
public List getBlankList() {
InquiryBean bean = new InquiryBean();
bean.setItemNumber("");
bean.setMaterial("");
bean.setDescription("");
bean.setQuantity("");
bean.setUnit("");
bean.setDeliveryDate(null);
return blankList;
}
Am i missing something????
Upvotes: 0
Views: 6576
Reputation: 30025
If you do not want to fill it later you could use a plain html table instead:
<table>
<tr>
<td>Student Number</td><td>Student Name</td> ...
</tr>
<tr>
<td></td><td></td> ...
</tr>
<!-- 9 rows following -->
</table>
If you want to fill it later you have to use the var
attribute of the dataTable and prepare a list with 10 (empty) elements in the backing bean:
<h:dataTable value=#{myBean.studentList} var="item">
<h:column>
<f:facet name="header">
<h:outputText value="Student Number" />
</f:facet>
<h:inputText value="#{item.studNum}" />
</h:column>
..
</h:dataTable>
Upvotes: 1
Reputation: 24251
You need to specify the value for the value
attribute (sorry, no pun intended). It's how you specify rows of the dataTable. The way you have it now it's specifying there should no (null) rows in the output table (if it only works).
That's why my suggestion is to declare some bean which would have a 10-elements collection available as some property (if that's your preference). And have an EL expression pointing to this bean's property in the value
attribute.
You can take a look at some examples on Internet (take a look at DataTableBean
there).
Basically your should:
faces-config.xml
if it's a plain JSF)value
attribute of the h:dataTable
component.UPDATE:
Following your update. Now you have a defined what seems a proper bean and its implementing class. However your 'blankList' is an empty collection (as exactly the name indicates). If you want to have 10 rows in the data table you basically need to call add()
method on your collection 10 times (or something similar).
Upvotes: 1