如何进入JSF datatable`

时间:2014-06-23 08:12:52

标签: java jsf

请帮助我...我希望我的JSF数据表如下所示,即每行中的员工姓名都在标记中。

<table>
<thead><tr>
   <th>Name</th>
   <th>Salary</th>
</tr></thead>
<tbody>
<tr class="employeeTableOddRow">
   <th>John</th>
   <td>2000.0</td>
</tr>
<tr>
   <th>Robert</th>     
   <td>3000.0</td>
</tr>
</table>

但我得到的如下。名称不在标签中。我尝试了很多组合但是无法实现它

<table>
<thead><tr>
   <th>Name</th>
   <th>Salary</th>
</tr></thead>
<tbody>
<tr class="employeeTableOddRow">
   <td>John</td>
   <td>2000.0</td>
</tr>
<tr>
   <td>Robert</td>
   <td>3000.0</td>
</tr>
</table>

编写的代码如下

<h:dataTable value="#{userData.employees}" var="employee">
<h:column>                  
      <f:facet name="header">Name</f:facet>                 
      #{employee.name}
   </h:column>
   <h:column>
      <f:facet name="header">Salary</f:facet>
      #{employee.salary}
   </h:column>
</h:dataTable>

请让我知道如何做到这一点

1 个答案:

答案 0 :(得分:1)

<h:dataTable value="#{userData.employees}" var="employee">
   <h:column>
      <f:facet name="header">
          <h:outputText value="Name" />
      </f:facet>
      <h:outputText value="#{employee.name}" />
   </h:column>
</h:dataTable>

示例here