[英]Sorting is not working in Primefaces datatable
在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
}
}
}
如果您在获取中填充了列表,则将无法使用。 如果每次都在get中填充列表,则对主要面孔进行排序将不起作用。 而是尝试将bean视域化,并在构造函数中填充列表,然后它将工作。
尝试这个:
private List<Employee> employees = new ArrayList<Employee>();
public List<Employee> getEmployees() {
if(employees.isEmpty()){
employees.addAll(empList());
}
return employees;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.