dynamicbindgridbean.java
来自「OperaMasks是一种基于J2EE的Web开发技术」· Java 代码 · 共 114 行
JAVA
114 行
/*
* $Id: DynamicBindGridBean.java,v 1.4 2008/08/15 03:02:02 libin 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.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.operamasks.faces.annotation.Action;
import org.operamasks.faces.annotation.BeforeRender;
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 org.operamasks.faces.util.ArrayUtils;
import demo.StockBean.Quote;
import demo.grid.GridBeanHelper;
import demo.grid.GridDataModel.TrainRecord;
@ManagedBean(scope = ManagedBeanScope.SESSION)
@SuppressWarnings( { "unused", "serial" })
public class DynamicBindGridBean {
public DynamicBindGridBean() {
Map<String, Object> config = new HashMap<String, Object>();
config.put("paged", Boolean.TRUE);
config.put("rows", new Integer(5));
this.gridConfig = config;
}
@SuppressWarnings("unchecked")
@Bind(id = "grid", attribute = "value")
private List data = GridBeanHelper.trainRecord;
@ComponentAttributes(id = "grid")
private Map<String, Object> gridConfig;
@Bind(id = "grid", attribute = "viewProvider")
private GridViewProvider provider = GridBeanHelper.getTrainViewProvider();
@Bind(id = "grid", attribute = "rowDataProvider")
private GridRowDataProvider rowProvider = GridBeanHelper
.getTrainRowProvider();
@Bind(id = "grid")
private UIDataGrid grid;
@BeforeRender
public void beforeRender(boolean isPostBack) {
if (!isPostBack) {
this.data = GridBeanHelper.trainRecord;
}
}
/**
* 使用页面绑定或者IoVC绑定方式为grid绑定的value,在grid中持有的只是ValueExpression对象,在运行时才求值;
* 直接调用grid.setValue会将实际的value设置到grid中,从而导致value被序列化以保持状态。
* 推荐的做法是更改grid所绑定的value的值,或者为grid设置dataProvider。
*/
@SuppressWarnings("unchecked")
@Action
public void train() {
grid.setViewProvider(GridBeanHelper.getTrainViewProvider());
grid.setRowDataProvider(GridBeanHelper.getTrainRowProvider());
this.data = GridBeanHelper.trainRecord;
grid.setFirst(0);
grid.setRows(4);
grid.rebind();
}
/**
* 使用页面绑定或者IoVC绑定方式为grid绑定的value,在grid中持有的只是ValueExpression对象,在运行时才求值;
* 直接调用grid.setValue会将实际的value设置到grid中,从而导致value被序列化以保持状态。
* 推荐的做法是更改grid所绑定的value的值,或者为grid设置dataProvider。
*/
@Action
public void stock() {
grid.setViewProvider(GridBeanHelper.getSingleHeaderStockViewProvider());
grid.setRowDataProvider(GridBeanHelper.getStockRowProvider());
this.data = Arrays.asList(GridBeanHelper.stockData);
grid.setFirst(0);
grid.setRows(10);
grid.rebind();
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?