gpt4 book ai didi

java - Primefaces 数据表中排序不起作用

转载 作者:行者123 更新时间:2023-12-01 17:33:28 24 4
gpt4 key购买 nike

排序在 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>

My Primefaces version is 3.0.M3 with JSF2 and 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 具有 View 范围并填充构造函数中的列表,然后它应该可以工作。

关于java - Primefaces 数据表中排序不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8724554/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com