【发布时间】:2012-01-04 09:25:58
【问题描述】:
排序在 Primefaces 数据表中不起作用。显示了我的 jsf 代码。我们需要在支持 bean 中做任何事情以使其正常工作吗?
<p:dataTable id="employees" value="#{employeeList.employees}"
var="employee" emptyMessage="No Employees found" rows="10"
paginator="true"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="5,10,15" rowIndexVar="rowIndex">
<p:column sortBy="#{employee.firstName}">
<f:facet name="header">
<h:outputText value="First Name" />
</f:facet>
<h:outputText value="#{employee.firstName}">
</h:outputText>
</p:column>
<p:column sortBy="#{employee.lastName}">
<f:facet name="header">
<h:outputText value="Last Name" />
</f:facet>
<h:outputText value="#{employee.lastName}" />
</p:column>
</p:dataTable>
我的 Primefaces 版本是 3.0.M3,带有 JSF2 和 Google Cloud SQL
EmployeeList.java:
public List<Employee> getEmployees() throws HibernateException, SQLException {
List<Employee> employees = new ArrayList<Employee>();
employees.addAll(empList());
}
我在 empList() 中的哪个位置编写了用于检索所有员工并返回所有员工的查询。
EmployeeList.java
@Component("employeeList")
@SessionScoped
@Repository
public class newb implements Serializable {
private static final long serialVersionUID = -2417394435764260084L;
public static HibernateTemplate hibernateTemplate;
@Autowired
public void setSessionFactory(SessionFactory sessionFactory)
{
this.hibernateTemplate = new HibernateTemplate(sessionFactory);
}
public List<Employee> getEmployees() throws HibernateException, SQLException {
List<Employee> employees = new ArrayList<Employee>();
employees.addAll(empList());
return employees;
}
@SuppressWarnings("unchecked")
public List<Employee> empList() {
try
{
List <Employee> result = hibernateTemplate.find("from Employee");
return result;
}
finally {
//close the session and user-supplied JDBC connection
}
}
}
【问题讨论】:
-
如果您尝试点击排序按钮会发生什么?
-
您的
<p:dataTable>标签是否在<h:form>中? -
点击排序箭头/列标题时,对信息没有影响。
-
是的,在
<h:form prependId="false">。 -
我在 GlassFish 3.1 上使用 PrimeFaces 3.0.M3 编译您的代码并且工作正常。
标签: java google-app-engine jsf-2 primefaces