Announcement

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

    How to clear setEmptyDisplayValue

    SmartGwt: SC_SNAPSHOT-2011-08-08/LGPL
    FireFox 7.0.1

    We have a scenario where we have a grid where based on an initial SelectItem, a second SelectItem either has no values and is not required or is required and has values. We do a .setEmptyDisplayValue on the second SelectItem so we can display something like "Not applicable" when it is empty. However, once we set this, the empty display value continues to appear after we do a setEditorValueMap and flag the SelectItem as .setRequired. Setting the EmptyDisplayValue to "" or null doesn't seem to change the behavior.

    Here's a test case demonstrating the problem. After clicking on "Add New", the "Type" column has only "-- Not applicable --" as an option, but after selecting "Item1" in the "Select Item" column, the "Type" column is loaded with a set of value but the "-- Not applicable --" still appears.

    Let me know if you need more information to respond on this.

    Ed Reddy
    Jenzabar, Inc.

    Main Code
    Code:
    public class Application implements EntryPoint {
    
    	public void onModuleLoad() {
    		
    		SampleGrid sg = new SampleGrid();
    		VLayout vLayout = createGridComponent("Sample Grid", sg);
    		vLayout.setWidth(600);
    		vLayout.draw();	
    	}
    	
    	public VLayout createGridComponent(String title, final ListGrid grid) {
    		DynamicForm df = new DynamicForm();
    		
    		StaticTextItem staticTextItem = new StaticTextItem();
    		staticTextItem.setShowTitle(false);
    		staticTextItem.setDefaultValue(title);
    		LinkItem addRowItem = new LinkItem();
    		addRowItem.setShowTitle(false);
    		addRowItem.setAlign(Alignment.RIGHT);
    		addRowItem.setValue("Add new");
    		
    		df.setFields(staticTextItem,addRowItem);
    
    		DynamicForm totalsForm = new DynamicForm();
    		totalsForm.setNumCols(6);
    		totalsForm.setColWidths("20%","20%","20%","20%","10%","10%");
    		totalsForm.setLayoutAlign(Alignment.RIGHT);
    		SpacerItem spacer = new SpacerItem();
    		spacer.setColSpan(4);
    		
    		
    		VLayout vlayout = new VLayout();
    		vlayout.addMember(df);
    		vlayout.addMember(grid);
    		vlayout.addMember(totalsForm);
    		
    		addRowItem.addClickHandler(new ClickHandler() {
    			
    			@Override
    			public void onClick(ClickEvent event) {
    				grid.startEditingNew();
    			}
    		});
    		return vlayout;
    	}
    SampleGrid
    Code:
    public class SampleGrid extends ListGrid {
    	
    	private SelectItem typeEditor;
    	private ListGridField selectItem2;
    	private SelectItem selectItemEditor;
    	private ListGridField type1;
    
    	public SampleGrid() {
    		setWidth("100%");
    		setHeight(150); 
    		setCanEdit(true);
    		setAutoFetchData(false);
    		setAutoSaveEdits(false);
    		setCanGroupBy(false);
    		addGridColumns();
    	}
    
    	protected void addGridColumns() {
    		selectItem2 = new ListGridField("selectItem1","Select Item");
    		LinkedHashMap<String, String> linkedhashMap = new LinkedHashMap<String, String>();
    		linkedhashMap.put("item1", "Item1");
    		linkedhashMap.put("item2", "Item2");
    		selectItemEditor = new SelectItem("selectItmeEditor");
    		selectItemEditor.setValueMap(linkedhashMap);
    		selectItem2.setEditorType(selectItemEditor);
    		
    		selectItem2.addChangedHandler(new ChangedHandler() {
    			
    			@Override
    			public void onChanged(ChangedEvent event) {
    				String val = event.getItem().getValue()+"";
    				if(val.equals("item1")){
    					type1.setRequired(true);
    					typeEditor.setAllowEmptyValue(false);
    					getTransactionTypeRecords();
    				}else{
    					type1.setRequired(false);
    					typeEditor.setAllowEmptyValue(true);
    					setEditorValueMap("type1", new LinkedHashMap<String, String>());
    				}
    			}
    		});
    		
    		type1 = new ListGridField("type1","Type");
    		typeEditor = new SelectItem("typeEditor");
    		typeEditor.setValueMap(new LinkedHashMap<String, String>());
    		typeEditor.setAllowEmptyValue(true);
    		typeEditor.setEmptyDisplayValue("--- Not applicable ---");
    		type1.setEditorType(typeEditor);
    
    		setFields(selectItem2, type1);
    	}
    	
    	
    	
    	private void getTransactionTypeRecords() {
    		type1.setRequired(true);
    		LinkedHashMap<String, String> map = new LinkedHashMap<String, String>();
    		for(int i=0;i<5;i++) {
    			map.put("type"+i,"Type"+i);
    		}
    		setEditorValueMap("type1", map);
    		
    	}
    
    }

    #2
    This looks like an already-fixed bug. Could you try with the latest patched build please?

    Comment

    Working...
    X