如何使用jsf 2.0显示带有空白行的数据表
我试图在页面加载时显示一个包含 10 行的空数据表,当我尝试使用下面的代码时,它不显示任何行。
<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>
需要帮助来显示带有空白列和行的数据表
更新
根据给定的解决方案我尝试了这种方式但无法解决问题
<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;
}
我错过了什么吗???
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
UPDATE
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????
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要指定
value
属性的值(抱歉,没有双关语)。这是指定数据表行的方式。现在的方式是指定输出表中不应有(空)行(如果它有效)。这就是为什么我的建议是声明一些 bean,它有一个 10 元素集合可用作某些属性(如果这是您的偏好)。并且在
value
属性中有一个指向该 bean 属性的 EL 表达式。您可以查看互联网上的一些示例 (看看那里的
DataTableBean
)。基本上你应该:
中的EL表达式指向该集合
属性。h:dataTable
组件的 value更新:
根据您的更新。现在您已经定义了一个看起来合适的 bean 及其实现类。但是,您的“blankList”是一个空集合(正如名称所示)。如果您希望数据表中有 10 行,您基本上需要对集合调用
add()
方法 10 次(或类似的操作)。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 theh: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).如果您不想稍后填充它,您可以使用纯 html 表格来代替:
如果您想稍后填充它,则必须使用 dataTable 的
var
属性,并且在支持 bean 中准备一个包含 10 个(空)元素的列表:If you do not want to fill it later you could use a plain html table instead:
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: