gwt 前端报表打印组件

阅读更多

package com.appdev.bsf.common.client.report;

import com.appdev.bsf.common.client.resources.CommonResourcesGenerator;
import com.smartgwt.client.widgets.form.DynamicForm;
import com.smartgwt.client.widgets.form.fields.FormItemIcon;
import com.smartgwt.client.widgets.form.fields.SelectItem;
import com.smartgwt.client.widgets.form.fields.events.FormItemClickHandler;
import com.smartgwt.client.widgets.layout.HLayout;

/**
 *
 *  
 * @category 例子(事件里面相应代码)

 *           DynamicForm form = event.getForm();

 *           String type = form.getValue("type").toString();//获取要导出报表的类型

 *           OperatorDataSource dataSource
 *           =operatorListGrid.getOperatorDataSource();
 *           //获取当前对应显示ListGrid的DataSource

 *           String criterias = dataSource.getCriterias().toString()
 *           .replace("{", "").replace("}", ""); //获取选择数据的条件

 *           map,type,clsUrl这三个参数必须传

 *           Window.open(GWT.getModuleBaseURL() + "ReportServlet?map=" +
 *           criterias + "&type=" + type + "&clsUrl=" +
 *           Operator.class.getName(), "report", "sdfs");

 *           //传参数的名字,Operator.class.getName()表示类路径
 */
public class GwtJasperReport extends HLayout {
    public GwtJasperReport(FormItemClickHandler formItemClickHandler) {
        setHeight(22);
        setWidth(180);

        ItemButton itemBtn = new ItemButton(formItemClickHandler);

        final DynamicForm df = new DynamicForm();
        df.setHeight(22);
        df.setWidth100();
        SelectItem item = new SelectItem("type", "报表类型");
        item.setWidth(125);
        item.setValueMap("PDF", "HTML", "Excel", "RTF");
        item.setDefaultValue("Excel");
        item.setIcons(itemBtn);
        df.setItems(item);

        addMember(df);
    }

    private class ItemButton extends FormItemIcon {
        public ItemButton(FormItemClickHandler clickHandler) {
            setSrc(CommonResourcesGenerator.generatorReportResource().export().getSafeUri().asString());
            setWidth(40);
            setHeight(22);
            setAttribute("hspace", 0);
            addFormItemClickHandler(clickHandler);
        }
    }
}

 

 

前端应用:

        GwtJasperReport report = new GwtJasperReport(new FormItemClickHandler() {

            @Override
            public void onFormItemClick(FormItemIconClickEvent event) {
                DynamicForm form = event.getForm();
                String type = form.getValue("type").toString();
                OperatorDataSource dataSource = operatorListGrid.getOperatorDataSource();
                String criterias = dataSource.getCriterias().toString().replace("{", "").replace("}", "");
                Window.open(GWT.getModuleBaseURL() + "ReportServlet?map=" + criterias + "&type=" + type
                        + "&clsUrl=" + Operator.class.getName(), "report", "sdfs");
            }
        });

你可能感兴趣的:(java,gwt,smartgwt)