Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Select Item in the Grid

    Hello all,
    I am using smart gwt2.2 on windows system, with browser Mozilla.
    In smart gwt I am using a ListGrid.And in that ListGrid for one field I have set the editor type to Select Item.

    Code:
    SelectItem item = new  SelectItem();
    ListGridField field = new ListGridField("Field", "Field");
    field.setEditorType(item);
    My problem is that is I set the simple string value map to the Select Item then it works fine, But while same list coming from server side and I try to set then it is giving this error,

    Uncaught JavaScript exception [this.formItem is undefined] in http://127.0.0.1:8888/nextenders/sc/modules/ISC_Forms.js, line 1831

    I am not getting at which place I am doing wrong.

    #2
    Can you include a source code relative to your Side server side code ?
    What do you want to set ?

    Victor

    Comment


      #3
      Code for Setting Editor Type
      Code:
      private static NTListGridField[] getFields(
      			List<FormControlMap> srcFormCtrlMapList,
      			Map<String, Object> srcformCtrlMap, FormControlMap map1) {
      		NTListGridField[] columns = new NTListGridField[srcFormCtrlMapList
      				.size()];
      		int i = 0;
      		for (FormControlMap map : srcFormCtrlMapList) {
      			Control control = (Control) map.getIsBean_2();
      			String str = UIControlUtil.getControlName(String.valueOf(control.getId()));
      			NTListGridField field = new NTListGridField(str, control.getName());
      			Layout mapLayout = map.getLayout();
      			if (mapLayout != null) {
      				ControlType controlType = mapLayout.getControlType();
      				if (controlType != null) {
      					FormItem item = null;
      					if (controlType.equals(ControlType.TEXTBOX)) {
      						item = new NTTextItem();
      					} else if (controlType.equals(ControlType.TEXTAREA)) {
      						item = new NTTextAreaItem();
      						item.setHeight(25);
      					} else if (controlType.equals(ControlType.DATE_TIME)) {
      						item = new NTDateTimeItem();
      						((NTDateTimeItem) item)
      								.setDisplayFormat(DateDisplayFormat.TOUSSHORTDATETIME);
      
      					} else if (controlType.equals(ControlType.CHECK_BOX)) {
      						item = new NTCheckBoxItem();
      					} else if (controlType.equals(ControlType.DATE)) {
      						field.setType(ListGridFieldType.DATE);
      					} else if (controlType.equals(ControlType.DROPDOWN)
      							|| controlType
      									.equals(ControlType.MULTI_CHOICE_LIST)) {
      						item = NTDropDownUtil.getDefaultDropDown(map,str,
      								false, false);
      					}
      					if (item != null) {
      						field.setEditorType(item);
      					}
      				}
      			columns[i] = field;
      			i++;
      		}
      		return columns;
      	}
      Code for getting select item
      My case is the Master_reference
      Code:
      /**
       * 
       */
      package com.nextenders.client.ui.util;
      
      import java.util.ArrayList;
      import java.util.LinkedHashMap;
      import java.util.List;
      import java.util.Map;
      
      import com.nextenders.client.beans.enums.BooleanValue;
      import com.nextenders.client.beans.enums.ControlType;
      import com.nextenders.client.beans.enums.DataType;
      import com.nextenders.client.beans.metadata.FormControlMap;
      import com.nextenders.client.beans.metadata.TableColumnMap;
      import com.nextenders.client.beans.settings.Data;
      import com.nextenders.client.beans.settings.Display;
      import com.nextenders.client.beans.settings.Layout;
      import com.nextenders.client.ui.triad.view.combobox.smartgwt.MasterReferenceSelectItem;
      import com.nextenders.client.widgets.smartgwt.NTSelectItem;
      import com.smartgwt.client.types.MultipleAppearance;
      import com.smartgwt.client.widgets.form.fields.FormItem;
      
      /**
       * @author sanjay.jain
       * 
       */
      public class NTDropDownUtil {
      	public static NTSelectItem getDefaultDropDown(FormControlMap map,String name,boolean isValidate,boolean isDisplaySetting) {
      		Data data = map.getData();
      		Layout layout = map.getLayout();
      		NTSelectItem item= null;
      		if(data.getDataType().equals(DataType.SIMPLE_REFERENCE))
      		{
      			item = new NTSelectItem();
      			setDataSettings(item,data);
      			UIControlUtil.setControlName(map.getControl().getId(), item);
      		}else if(data.getDataType().equals(DataType.MASTER_REFERENCE))
      		{
      			List<TableColumnMap> list = data.getTableColumnMapList();
      			final List<Long> list1 = new ArrayList<Long>();
      			if(list!=null && list.size()>0)
      			{
      				for(TableColumnMap map2:list)
      				{
      					list1.add(map2.getId());
      				}
      			}
      			item = new MasterReferenceSelectItem(name,MultipleAppearance.PICKLIST,list1);
      		}
      		
      		
      		if(layout.getControlType().equals(ControlType.MULTI_CHOICE_LIST))
      		{
      			item.setMultiple(true);
      		}else
      		{
      			item.setMultiple(false);
      		}
      			
      		if(isDisplaySetting)
      		{
      			setDisplaySettings(item,map.getDefaultDisplay());
      		}
      		if(isValidate)
      		{
      			item.setAttribute("validation",map.getValidation());
      			UIControlUtil.setValidateImage(item);
      		}
      		return item;
      	}
      	
      
      	private static void setDataSettings(FormItem item,
      			Data data) {
      		if(data!=null)
      		{
      			List<String> list = data.getFkStringValues();
      			if(list!=null)
      			{
      				 LinkedHashMap<String, String> valueMap = new LinkedHashMap<String, String>();  
      				for (String value : list)
      				{
      					valueMap.put(value, value);
      				}
      				item.setValueMap(valueMap);
      			}
      		}
      		
      	}
      
      
      	private static void setDisplaySettings(FormItem item,
      			Display display) {
      		item.setTitle(display.getDisplayText());
      		item.setValue(display.getDefaultValue());
      		if (BooleanValue.booleanValue(display.getShowHelp())) {
      		    UIControlUtil.setHelpText(item, display.getHelpText());
      		}
      	}
      
      }
      Master Reference Select Item Class
      Code:
      /**
       * 
       */
      package com.nextenders.client.ui.triad.view.combobox.smartgwt;
      
      import java.util.ArrayList;
      import java.util.HashMap;
      import java.util.LinkedHashMap;
      import java.util.List;
      import java.util.Set;
      import java.util.TreeSet;
      
      import com.nextenders.client.beans.BeanFilter;
      import com.nextenders.client.beans.CommunicationObject;
      import com.nextenders.client.beans.enums.DAOFacadeMethods;
      import com.nextenders.client.beans.enums.FacadeType;
      import com.nextenders.client.beans.enums.FilterType;
      import com.nextenders.client.beans.transaction.CellTransaction;
      import com.nextenders.client.beans.transaction.RowTransaction;
      import com.nextenders.client.stub.callbacks.NCallback;
      import com.nextenders.client.stub.rpcaller.ProcessCaller;
      import com.nextenders.client.util.factory.RequestFactory;
      import com.nextenders.client.util.other.StringUtil;
      import com.nextenders.client.widgets.smartgwt.NTSelectItem;
      import com.smartgwt.client.types.MultipleAppearance;
      
      /**
       * @author sanjay.jain
       * 
       */
      public class MasterReferenceSelectItem extends NTSelectItem {
      
      	LinkedHashMap<String, String> valueMap = null;
      
      	public MasterReferenceSelectItem(String name,
      			MultipleAppearance appearance, List<Long> list) {
      		super(name, appearance, true);
      		if (valueMap == null) {
      			BeanFilter filter = new BeanFilter(new CellTransaction());
      			StringUtil.setFilterList(filter, "tableColumnMap.id", list,
      					FilterType.IN);
      			StringUtil.setFetchModesJoinList(filter, "table", "rowTransaction",
      					"rowTransaction.createdUser", "fkFormTransaction",
      					"fkRowTransaction", "validation", "fkFormTransactionList",
      					"fkRowTransactionList", "valueList", "tableColumnMap");
      			CommunicationObject request = RequestFactory.getBeanFilterRequest(
      					FacadeType.DAOFacade, DAOFacadeMethods.getBeanFilterData
      							.toString(), filter);
      			ProcessCaller.performAction(request, new NCallback(
      					MasterReferenceSelectItem.this));
      		}
      
      	}
      
      	@Override
      	public void doAfterCallback(Object result) {
      		super.doAfterCallback(result);
      		HashMap<String, Object> resultMap = (HashMap<String, Object>) ((CommunicationObject) result)
      				.getMapResult();
      		if (resultMap != null) {
      			List<CellTransaction> list = (List<CellTransaction>) resultMap
      					.get(CellTransaction.class.toString());
      			if (list != null && list.size() > 0) {
      				Set<RowTransaction> rowTxnSet = new TreeSet<RowTransaction>();
      				for (CellTransaction ct : list) {
      					if (ct.getRowTransaction() != null)
      						rowTxnSet.add(ct.getRowTransaction());
      				}
      				if (rowTxnSet.size() > 0) {
      					valueMap = new LinkedHashMap<String, String>();
      					for (RowTransaction rt : rowTxnSet) {
      						List<String> tempList = new ArrayList<String>();
      						for (CellTransaction ct : list) {
      
      							if (ct.getRowTransaction() != null
      									&& rt.getId() == ct.getRowTransaction()
      											.getId()) {
      								tempList.add(ct.getValue());
      							}
      						}
      						valueMap
      								.put(String.valueOf(rt.getId()), StringUtil
      										.returnDelimiterSeperatedStrings(
      												tempList, ","));
      					}
      					setValueMap(valueMap);
      				}
      			}
      		}
      	}
      }

      Comment

      Working...
      X