Quantcast
Channel: SmartClient Forums
Viewing all articles
Browse latest Browse all 4756

4.0p upgrade problems with addWindowClosingHandler

$
0
0
I was using smartgwt3.1p and upgrading to 4.0p (10.07.13) I have problems with addWindowClosingHandler():

(adapted from http://www.smartclient.com/smartgwtee/showcase/#excel_export)

Code:

package zedes2.client.test;

import java.util.LinkedHashMap;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.Window.ClosingEvent;
import com.google.gwt.user.client.Window.ClosingHandler;
import com.smartgwt.client.data.DSRequest;
import com.smartgwt.client.data.DataSource;
import com.smartgwt.client.types.Alignment;
import com.smartgwt.client.types.Autofit;
import com.smartgwt.client.types.ExportDisplay;
import com.smartgwt.client.types.ExportFormat;
import com.smartgwt.client.util.EnumUtil;
import com.smartgwt.client.util.SC;
import com.smartgwt.client.widgets.IButton;
import com.smartgwt.client.widgets.events.ClickHandler;
import com.smartgwt.client.widgets.form.DynamicForm;
import com.smartgwt.client.widgets.form.fields.BooleanItem;
import com.smartgwt.client.widgets.form.fields.FormItem;
import com.smartgwt.client.widgets.form.fields.SelectItem;
import com.smartgwt.client.widgets.grid.ListGrid;
import com.smartgwt.client.widgets.grid.ListGridField;
import com.smartgwt.client.widgets.layout.HLayout;
import com.smartgwt.client.widgets.layout.VLayout;

public class TestingModule implements EntryPoint {

    public void onModuleLoad() {

        com.google.gwt.user.client.Window.addWindowClosingHandler(new ClosingHandler() {
           
            @Override
            public void onWindowClosing(ClosingEvent event) {
                SC.say("closing");
            }
        });
       
       
        DataSource worldDSExport = DataSource.get("worldDSExport"); 
         
        final ListGrid countryList = new ListGrid(); 
        countryList.setWidth(500); 
        countryList.setAlternateRecordStyles(true); 
        countryList.setDataSource(worldDSExport); 
        countryList.setAutoFetchData(true); 
 
        ListGridField countryName = new ListGridField("countryName", "Country"); 
        ListGridField capital = new ListGridField("capital", "Capital"); 
        ListGridField continent = new ListGridField("continent", "Continent"); 
 
        countryList.setFields(countryName, capital, continent); 
        countryList.setAutoFitData(Autofit.VERTICAL); 
        countryList.setShowFilterEditor(true); 
        countryList.setAutoFitMaxRecords(10); 
 
        final DynamicForm exportForm = new DynamicForm(); 
        exportForm.setWidth(300); 
 
        SelectItem exportTypeItem = new SelectItem("exportType", "Export Type"); 
        exportTypeItem.setWidth("*"); 
        exportTypeItem.setDefaultToFirstOption(true); 
 
        LinkedHashMap valueMap = new LinkedHashMap(); 
        valueMap.put("csv", "CSV (Excel)"); 
        valueMap.put("xml", "XML"); 
        valueMap.put("json", "JSON"); 
        valueMap.put("xls", "XLS (Excel97)"); 
        valueMap.put("ooxml", "XLSX (Excel2007/OOXML)"); 
 
        exportTypeItem.setValueMap(valueMap); 
 
        BooleanItem showInWindowItem = new BooleanItem(); 
        showInWindowItem.setName("showInWindow"); 
        showInWindowItem.setTitle("Show in Window"); 
        showInWindowItem.setAlign(Alignment.LEFT); 
 
        exportForm.setItems(exportTypeItem, showInWindowItem); 
 
        IButton exportButton = new IButton("Export"); 
        exportButton.addClickHandler(new ClickHandler() { 
            public void onClick(com.smartgwt.client.widgets.events.ClickEvent event) { 
                String exportAs = (String) exportForm.getField("exportType").getValue(); 
 
                FormItem item = exportForm.getField("showInWindow"); 
                boolean showInWindow =  item.getValue() == null ? false : (Boolean) item.getValue(); 
 
                if(exportAs.equals("json")) { 
                    // JSON exports are server-side only, so use the OperationBinding on the DataSource 
                    DSRequest dsRequestProperties = new DSRequest(); 
                    dsRequestProperties.setOperationId("customJSONExport"); 
                    dsRequestProperties.setExportDisplay(showInWindow ? ExportDisplay.WINDOW : ExportDisplay.DOWNLOAD); 
 
                    countryList.exportData(dsRequestProperties); 
                } else { 
                  // exportAs is either XML or CSV, which we can do with requestProperties 
                    DSRequest dsRequestProperties = new DSRequest(); 
                    dsRequestProperties.setExportAs((ExportFormat)EnumUtil.getEnum(ExportFormat.values(), exportAs)); 
                    dsRequestProperties.setExportDisplay(showInWindow ? ExportDisplay.WINDOW : ExportDisplay.DOWNLOAD); 
 
                    countryList.exportData(dsRequestProperties); 
                } 
            } 
        }); 
 
        VLayout layout = new VLayout(15); 
        layout.setAutoHeight(); 
 
        HLayout formLayout = new HLayout(15); 
        formLayout.addMember(exportForm); 
        formLayout.addMember(exportButton); 
        layout.addMember(formLayout); 
 
        layout.addMember(countryList); 
 
        layout.draw(); 
    }

}

When I export the list, onWindowClosing() is being called. The same for
Code:

DataSource.get("dynamicFileDownload").downloadFile(vertrag, "f_datei",
                properties);

The behavior was different in 3.1p, so I think this is a bug.

Viewing all articles
Browse latest Browse all 4756

Trending Articles