eventgridbean.java

来自「OperaMasks是一种基于J2EE的Web开发技术」· Java 代码 · 共 124 行

JAVA
124
字号
/*
 * $Id: EventGridBean.java,v 1.4 2008/08/19 11:25:14 jacky Exp $
 *
 * Copyright (C) 2006 Operamasks Community.
 * Copyright (C) 2000-2006 Apusic Systems, Inc.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see http://www.gnu.org/licenses.
 */
package demo.grid.dynamic;

import java.util.HashMap;
import java.util.Map;

import org.operamasks.faces.annotation.Action;
import org.operamasks.faces.annotation.Bind;
import org.operamasks.faces.annotation.ComponentAttributes;
import org.operamasks.faces.annotation.ManagedBean;
import org.operamasks.faces.annotation.ManagedBeanScope;
import org.operamasks.faces.component.grid.CheckboxSelectionModel;
import org.operamasks.faces.component.grid.GridColumn;
import org.operamasks.faces.component.grid.GridColumnModel;
import org.operamasks.faces.component.grid.GridHeaderModel;
import org.operamasks.faces.component.grid.GridSelectionModel;
import org.operamasks.faces.component.grid.impl.UIDataGrid;
import org.operamasks.faces.component.grid.provider.GridRowDataProvider;
import org.operamasks.faces.component.grid.provider.GridViewProvider;

import demo.StockBean.Quote;
import demo.grid.GridBeanHelper;

@ManagedBean(scope = ManagedBeanScope.REQUEST)
@SuppressWarnings( { "unused", "serial" })
public class EventGridBean {
	@Bind(id = "grid", attribute = "value")
	private Quote[] data = GridBeanHelper.stockData;

	@ComponentAttributes(id = "grid")
	public Map<String, Object> getGridConfig() {
		Map<String, Object> config = new HashMap<String, Object>();
		config.put("paged", Boolean.TRUE);
		config.put("rows", new Integer(10));
		// config.put("remoteSort", Boolean.TRUE);
		return config;
	}

	@Bind(id = "grid", attribute = "viewProvider")
	private GridViewProvider provider = GridBeanHelper.getStockViewProvider();

	@Bind(id = "grid", attribute = "rowDataProvider")
	private GridRowDataProvider rowProvider = GridBeanHelper
			.getStockRowProvider();

	@Bind
	private String selectionchange_result;
	@Bind
	private String dblclick_result;
	@Bind
	private String beforedataload_result;

	@Bind
	private UIDataGrid grid;

	@Bind
	private int selectedRow;

	@Action
	public void selectRow() {
		int[] selections = new int[] { selectedRow };
		grid.setSelections(selections);
	}
    @Action
    public void grid_onrowdeselect() {
        int[] selections = grid.getSelections();
        StringBuilder buf = new StringBuilder();
        if (selections.length > 0) {
            selectedRow = selections[0];
            buf.append("selectionchange:");
            for (int row = 0; row < selections.length; buf.append(
                    row > 0 ? ", " : "").append(selections[row++]))
                ;
        }
        this.selectionchange_result = buf.toString();
    }

	@Action
	public void grid_onrowselect() {
		int[] selections = grid.getSelections();
		StringBuilder buf = new StringBuilder();
		if (selections.length > 0) {
			selectedRow = selections[0];
			buf.append("selectionchange:");
			for (int row = 0; row < selections.length; buf.append(
					row > 0 ? ", " : "").append(selections[row++]))
				;
		}
		this.selectionchange_result = buf.toString();
	}

	@Action
	public void grid_ondblclick() {
		int[] selections = grid.getSelections();
		StringBuilder buf = new StringBuilder();
		if (selections.length > 0) {
			selectedRow = selections[0];
			buf.append("dblclick:");
			for (int row = 0; row < selections.length; buf.append(
					row > 0 ? ", " : "").append(selections[row++]))
				;
		}
		this.dblclick_result = buf.toString();
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?