我找到了这个JSF 教程,它展示了如何使用分页和排序创建 JSF 表
<%@taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@taglib uri="http://myfaces.apache.org/tomahawk" prefix="t"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<f:view>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Effective datatable paging and sorting at DAO level</title>
</head>
<body>
<h:form id="form">
<%-- The sortable datatable --%>
<h:dataTable value="#{myBean.dataList}" var="item">
<h:column>
<f:facet name="header">
<h:commandLink value="ID" actionListener="#{myBean.sort}">
<f:attribute name="sortField" value="id" />
</h:commandLink>
</f:facet>
<h:outputText value="#{item.id}" />
</h:column>
<h:column>
<f:facet name="header">
<h:commandLink value="Name" actionListener="#{myBean.sort}">
<f:attribute name="sortField" value="name" />
</h:commandLink>
</f:facet>
<h:outputText value="#{item.name}" />
</h:column>
<h:column>
<f:facet name="header">
<h:commandLink value="Value" actionListener="#{myBean.sort}">
<f:attribute name="sortField" value="value" />
</h:commandLink>
</f:facet>
<h:outputText value="#{item.value}" />
</h:column>
</h:dataTable>
<%-- The paging buttons --%>
<h:commandButton value="first" action="#{myBean.pageFirst}"
disabled="#{myBean.firstRow == 0}" />
<h:commandButton value="prev" action="#{myBean.pagePrevious}"
disabled="#{myBean.firstRow == 0}" />
<h:commandButton value="next" action="#{myBean.pageNext}"
disabled="#{myBean.firstRow + myBean.rowsPerPage >= myBean.totalRows}" />
<h:commandButton value="last" action="#{myBean.pageLast}"
disabled="#{myBean.firstRow + myBean.rowsPerPage >= myBean.totalRows}" />
<h:outputText value="Page #{myBean.currentPage} / #{myBean.totalPages}" />
<br />
<%-- The paging links --%>
<t:dataList value="#{myBean.pages}" var="page">
<h:commandLink value="#{page}" actionListener="#{myBean.page}"
rendered="#{page != myBean.currentPage}" />
<h:outputText value="<b>#{page}</b>" escape="false"
rendered="#{page == myBean.currentPage}" />
</t:dataList>
<br />
<%-- Set rows per page --%>
<h:outputLabel for="rowsPerPage" value="Rows per page" />
<h:inputText id="rowsPerPage" value="#{myBean.rowsPerPage}" size="3" maxlength="3" />
<h:commandButton value="Set" action="#{myBean.pageFirst}" />
<h:message for="rowsPerPage" errorStyle="color: red;" />
<%-- Cache bean with data list, paging and sorting variables for next request --%>
<t:saveState value="#{myBean}" />
</h:form>
</body>
</html>
</f:view>
这个表可以在没有Tomahawk
库的情况下使用吗?我想尽可能多地使用干净的 JSF?可以仅使用标准 JSF 标记编辑此代码而不更改分页和排序吗?
最良好的祝愿