首先在放置滚动组件的页面的支撑bean中定义如下方法:
************************************************************************
***********************************
/**
* <p>Scroll to the page that contains the specified row
number.</p>
*
* @param row Desired row number
*/
public void scroll(int row) {
int rows = data.getRows();
if (rows < 1) {
return; // Showing entire table already
}
if (row < 0) {
data.setFirst(0);
} else if (row >= data.getRowCount()) {
data.setFirst(data.getRowCount() - 1);
} else {
data.setFirst(row - (row % rows));
}
}
/**
* Handles the ActionEvent generated as a result of clicking on a
* link that points a particular page in the result-set.
*/
public void processScrollEvent(ActionEvent event) {
int currentRow = 1;
// FacesContext context = FacesContext.getCurrentInstance();
UIComponent component = event.getComponent();
Integer curRow = (Integer)
component.getAttributes().get("currentRow");
if (curRow != null) {
currentRow = curRow.intValue();
}
// scroll to the appropriate page in the ResultSet.
scroll(currentRow);
}
************************************************************************
*****************************************************
页面中的dataTable一定要记得和UIdata的实例data绑定: bingding="#{
RightsBacking.data}",这样就可以通过操作UIdata的实例data操作
数据。
========================================================================
====================================================
<h:dataTable id="rightsView" value="#{RightsBacking.listRights}"
var="list" binding="#{RightsBacking.data}"
rendered="#{RightsBacking.isHasRights}" rows="5">
<h:column>
<f:facet name="header">
- 1
- 2
前往页