blob: 2225c1493ac5fd78ddac8c21ae5c77f430584f8e [file]
/*
* Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/
/*
* $Id: ResultSetBean.java,v 1.1 2005/11/03 03:00:23 SherryShen Exp $
*/
package demo.model;
import com.sun.org.apache.commons.logging.Log;
import com.sun.org.apache.commons.logging.LogFactory;
import jakarta.faces.component.UIComponent;
import jakarta.faces.component.UIData;
import jakarta.faces.context.FacesContext;
import jakarta.faces.event.ActionEvent;
import java.util.ArrayList;
import java.util.List;
/**
* <p>Backing file bean for <code>ResultSet</code> demo.</p>
*/
public class ResultSetBean {
private static Log log = LogFactory.getLog(ResultSetBean.class);
private List list = null;
public ResultSetBean() {
}
public List getList() {
// Construct a preconfigured customer list lazily.
if (list == null) {
list = new ArrayList();
for (int i = 0; i < 1000; i++) {
list.add(new CustomerBean(Integer.toString(i),
"name_" + Integer.toString(i),
"symbol_" + Integer.toString(i), i));
}
}
return list;
}
public void setList(List newlist) {
this.list = newlist;
}
// -------------------------------------------------------- Bound Components
/**
* <p>The <code>UIData</code> component representing the entire table.</p>
*/
private UIData data = null;
public UIData getData() {
return data;
}
public void setData(UIData data) {
this.data = data;
}
// ---------------------------------------------------------- Action Methods
/**
* <p>Scroll directly to the first page.</p>
*/
public String first() {
scroll(0);
return (null);
}
/**
* <p>Scroll directly to the last page.</p>
*/
public String last() {
scroll(data.getRowCount() - 1);
return (null);
}
/**
* <p>Scroll forwards to the next page.</p>
*/
public String next() {
int first = data.getFirst();
scroll(first + data.getRows());
return (null);
}
/**
* <p>Scroll backwards to the previous page.</p>
*/
public String previous() {
int first = data.getFirst();
scroll(first - data.getRows());
return (null);
}
/**
* <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;
if (log.isTraceEnabled()) {
log.trace("TRACE: ResultSetBean.processScrollEvent ");
}
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);
}
}