I am creating a FormItem, which is used as a FilterEditor. The first time I click on it, everything works properly. The second time, a JavaScript error pops up stating that form is null, and the popup is empty. Any subsequent times I click on the Filter's icon, the form items have a null JsObject tied to them:
In my main class, I call it like so:
Code:
package com.smartgwt.client; import java.util.Date; import com.smartgwt.client.data.Criteria; import com.smartgwt.client.types.Alignment; import com.smartgwt.client.types.VerticalAlignment; import com.smartgwt.client.util.SC; import com.smartgwt.client.widgets.Window; import com.smartgwt.client.widgets.form.DynamicForm; import com.smartgwt.client.widgets.form.fields.ButtonItem; import com.smartgwt.client.widgets.form.fields.CanvasItem; import com.smartgwt.client.widgets.form.fields.DateItem; import com.smartgwt.client.widgets.form.fields.FormItem; import com.smartgwt.client.widgets.form.fields.FormItemIcon; import com.smartgwt.client.widgets.form.fields.events.ClickEvent; import com.smartgwt.client.widgets.form.fields.events.ClickHandler; import com.smartgwt.client.widgets.form.fields.events.IconClickEvent; import com.smartgwt.client.widgets.form.fields.events.IconClickHandler; import com.smartgwt.client.widgets.grid.ListGrid; public class DateRangeItem extends FormItem { protected final ListGrid grid; protected final String dateField; // = "Report"; protected final Window popup = new Window(); protected final DynamicForm form = new DynamicForm(); protected final DateItem startDate; protected final DateItem endDate; protected final ButtonItem thirtyDaysButton = new ButtonItem("last30", "Last 30 Days"); protected final ButtonItem sixtyDaysButton = new ButtonItem("last60", "Last 60 Days"); protected final ButtonItem ninetyDaysButton = new ButtonItem("last90", "Last 90 Days"); protected final ButtonItem filterButton = new ButtonItem("addFilter", "Add Filter"); public DateRangeItem(ListGrid listGrid, String dateField) { super(); this.grid = listGrid; this.dateField = dateField; startDate = new DateItem("start" + dateField + "Date"); endDate = new DateItem("end" + dateField + "Date"); addIconClickHandler(new IconClickHandler() { public void onIconClick(IconClickEvent event) { selectDate(); } }); FormItemIcon icon = new FormItemIcon(); icon.setPrompt("Select date range"); icon.setSrc("date_control.png"); setIcons(icon); setIconHeight(18); setIconWidth(18); setIconVAlign(VerticalAlignment.CENTER); setShowPickerIcon(false); // setPickerIconWidth(16); // setPickerIconHeight(16); // setPickerIconSrc("date_control.png"); // setShowPickerIcon(true); setTitle("Select Date Range"); startDate.setDefaultValue(new Date(System.currentTimeMillis() - calcDaysInMillis(90))); // Default to 90 days prior endDate.setDefaultValue(new Date()); thirtyDaysButton.setEndRow(false); thirtyDaysButton.setAlign(Alignment.CENTER); thirtyDaysButton.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { startDate.setAttribute("value", new Date(System.currentTimeMillis() - calcDaysInMillis(30))); endDate.setAttribute("value", new Date()); } }); sixtyDaysButton.setStartRow(false); sixtyDaysButton.setEndRow(false); sixtyDaysButton.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { startDate.setValue(new Date(System.currentTimeMillis() - calcDaysInMillis(60))); endDate.setValue(new Date()); } }); ninetyDaysButton.setStartRow(false); ninetyDaysButton.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { startDate.setValue(new Date(System.currentTimeMillis() - calcDaysInMillis(90))); endDate.setValue(new Date()); } }); filterButton.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { Criteria criteria = grid.getFilterEditorCriteria(); if (criteria == null) criteria = new Criteria(); criteria.addCriteria(form.getValuesAsCriteria()); grid.invalidateCache(); grid.filterData(criteria); popup.hide(); } }); popup.setTitle("Filter on " + dateField + " Date"); popup.setWidth(500); popup.setHeight(300); popup.centerInPage(); popup.setIsModal(true); popup.addItem(form); } protected void selectDate() { form.setItems(startDate, endDate, thirtyDaysButton, new DoubleButtonItem(sixtyDaysButton, ninetyDaysButton), filterButton); popup.show(); } private long calcDaysInMillis(int days) { return ((long)1000 * 60 * 60 * 24 * days); } protected class DoubleButtonItem extends CanvasItem { public DoubleButtonItem(ButtonItem button1, ButtonItem button2) { DynamicForm innerForm = new DynamicForm(); innerForm.setItems(button1, button2); button1.setAlign(Alignment.CENTER); button2.setAlign(Alignment.CENTER); this.setCanvas(innerForm); this.setWidth(60); this.setAttribute("showTitle", false); } } }
Code:
ListGridField reportDateField = new ListGridField("reportDate"); reportDateField.setFilterEditorType(new DateRangeItem(listGrid, "Report")); listGrid.setFields(reportDateField);
Comment