Announcement

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

  • Isomorphic
    replied
    Is there something wrong with just getValue()?

    Leave a comment:


  • vinodnarayankar
    replied
    Any update on below issue

    Leave a comment:


  • vinodnarayankar
    replied
    SelectItem MonthItem = new SelectItem ();
    LinkedHashMap<String, String> monthList = new LinkedHashMap<String, String>();
    monthList.put("1234","Jan");
    monthList.put("1235","Feb");
    monthList.put("1236","Mar");
    monthList.put("1237","Apr");

    monthItem.setValueMap( monthList);

    In combobox i will see Jan,Feb,MarApr. when use selects Jan, i would like to read 1234 which is value id jan month. Same for FEb.

    What property shall i use to read the key of the combo box? at present i am using reportParams.getValueAsString("monthItem") and its returning Jan, but i want 1234. what shall i do? which property shall i use?

    Leave a comment:


  • vinodnarayankar
    replied
    Ok, thanks for the reply. ClearValue() works.

    Thanks
    Ps:I send you the code so that you can walk through the code. Apologies for not sending with datasource. Thanks for the help on this..

    Leave a comment:


  • Isomorphic
    replied
    We can't run your test case exactly as written since we don't have your dataSources but the basic issue appears to be that you're clearing the value before you apply the new valueMap.

    clearValue() will cause the item to reset to the default. If defaultToFirstOption is true, that default will be the first item in the valueMap.

    Here's a simple example with no dataSources demonstrating this.

    Code:
    import com.google.gwt.core.client.EntryPoint;
    import com.smartgwt.client.widgets.form.DynamicForm;
    import com.smartgwt.client.widgets.form.fields.SelectItem;
    import com.smartgwt.client.widgets.form.fields.events.ChangedEvent;
    import com.smartgwt.client.widgets.form.fields.events.ChangedHandler;
    
    public class DefaultToFirstOption implements EntryPoint {
    
        @Override
        public void onModuleLoad() {
            
            DynamicForm form = new DynamicForm();
            
            SelectItem masterItem = new SelectItem("master");
            masterItem.setValueMap("List 1", "List 2", "List 3");
            
            final SelectItem dependentItem = new SelectItem("dependent");
            // Only have to set this once
            dependentItem.setDefaultToFirstOption(true);
            
            masterItem.addChangedHandler(new ChangedHandler() {
                
                @Override
                public void onChanged(ChangedEvent event) {
                    if (event.getValue() == null) return;
                    String value = (String)event.getValue();
                    
                    String[] valueMap;
                    if (value.equals("List 1")) {
                        valueMap = list1;
                    } else if (value.equals("List 2")) {
                        valueMap = list2;
                    } else {
                        valueMap = list3;
                    }
                    
                    // setValueMap
                    dependentItem.setValueMap(valueMap);
                    // clear value so it resets to default (first option)
                    dependentItem.clearValue();
                }
            });
            
            form.setItems(masterItem, dependentItem);
            form.draw();
            
            
        }
        private String[] list1 = new String[] {
                "Option 11",
                "Option 12",
                "Option 13"
        };
    
        private String[] list2 = new String[] {
                "Option 21",
                "Option 22",
                "Option 23"
        };
        private String[] list3 = new String[] {
                "Option 31",
                "Option 32",
                "Option 33"
        };
    }

    Leave a comment:


  • Vinod.Narayankar
    replied
    Now i am using DSCallback methiod to retreive the list and bind it.
    The code is working fine. but i am not able set default selection in combobox.

    I tried with "selectItem.setDefaultToFirstOption(true) ".

    Iid not find any luck.

    Please find one the method which i am using. I also attached detailed code.

    ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    public void getMonths(Record[] recordDR,String selectedDateRangeType ,SelectItem selectItem,String selectedYear)
    {
    selectItem.clearValue();
    LinkedHashMap<String, String> monthList = new LinkedHashMap<String, String>();
    int cnt = 0; boolean flag= true;
    String StrColumn = null;
    if(selectedDateRangeType.equalsIgnoreCase("Monthly"))
    StrColumn ="MONTH_SHORT_NAME";
    if(selectedDateRangeType.equalsIgnoreCase("Quartely"))
    StrColumn ="QU_QUARTER_SHORT_NAME";//"QU_QUARTER_SHORT_NAME";
    if(selectedDateRangeType.equalsIgnoreCase("Yearly"))
    StrColumn="QU_QUARTER_SHORT_NAME";
    String strTemp = null;
    for (Record i : recordDR)
    {
    if(flag)
    cnt++;
    String b = i.getAttributeAsString("YEAR_NUM");
    if(b.equalsIgnoreCase(selectedYear))
    {
    monthList.put(i.getAttribute(StrColumn),i.getAttributeAsString(StrColumn));
    flag= false;
    }
    }
    selectItem.setValueMap( monthList);
    // if(recordDR.length>0)
    // selectItem.setValue( recordDR[cnt-1].getAttributeAsString(StrColumn));
    selectItem.setDefaultToFirstOption(true);
    }
    Attached Files

    Leave a comment:


  • Isomorphic
    replied
    SelectItems do not fully support having their optionDataSource modified at runtime like this.
    The easiest way to implement this pattern is probably to use separate selectItems for each optionDataSource (and defining the optionDataSource, displayField, valueField and defaultToFirstOption properties when the item is first created). You can implement this in your app by
    - either lazily creating them and using 'form.setItems()' to update the form at runtime,
    - or if you're dealing with a small number like this, having both defined and present in the form but show() / hide() ing the appropriate item depending on which dataSource you're intested in.

    Leave a comment:


  • Vinod.Narayankar
    started a topic Combobox selection issue

    Combobox selection issue

    Version: Smart GWT 3.0
    browser IE 8.0

    I have requirement where in I need to fill the combo box dynamically .
    at present its binding data . But it is not selecting the first option as default.
    This application has been built using "built-in-ds" shared by smart GWT.


    I have modified the in buildinDS.java file.


    package com.smartgwt.sample.client;

    import com.google.gwt.core.client.EntryPoint;
    import com.smartgwt.client.core.KeyIdentifier;
    import com.smartgwt.client.data.DataSource;
    import com.smartgwt.client.data.Record;
    import com.smartgwt.client.types.SelectionStyle;
    import com.smartgwt.client.types.SortArrow;
    import com.smartgwt.client.util.KeyCallback;
    import com.smartgwt.client.util.Page;
    import com.smartgwt.client.util.SC;
    import com.smartgwt.client.widgets.IButton;
    import com.smartgwt.client.widgets.Label;
    import com.smartgwt.client.widgets.events.ClickEvent;
    import com.smartgwt.client.widgets.events.ClickHandler;
    import com.smartgwt.client.widgets.form.DynamicForm;
    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.grid.ListGridRecord;
    import com.smartgwt.client.widgets.grid.events.RecordClickEvent;
    import com.smartgwt.client.widgets.grid.events.RecordClickHandler;
    import com.smartgwt.client.widgets.layout.HLayout;
    import com.smartgwt.client.widgets.layout.VStack;
    import com.smartgwt.client.widgets.viewer.DetailViewer;

    /**
    * Entry point classes define <code>onModuleLoad()</code>.
    */
    public class BuiltInDS implements EntryPoint {
    private DynamicForm boundForm;
    private DetailViewer boundViewer;

    private SelectItem items;

    /**
    * This is the entry point method.
    */
    public void onModuleLoad() {
    KeyIdentifier debugKey = new KeyIdentifier();
    debugKey.setCtrlKey(true);
    debugKey.setKeyName("D");

    Page.registerKey(debugKey, new KeyCallback() {
    public void execute(String keyName) {
    SC.showConsole();
    }
    });
    ListGrid grid = new ListGrid();

    grid.setWidth(130);
    grid.setLeaveScrollbarGap(false);
    grid.setShowSortArrow(SortArrow.NONE);
    grid.setCanSort(false);
    grid.setFields(new ListGridField("dsTitle", "Select a DataSource"));
    grid.setData(new ListGridRecord[]{
    new DSRecord("Animals", "animals"),
    new DSRecord("Office Supplies", "supplyItem"),
    new DSRecord("Employees", "employees")}
    );
    grid.setSelectionType(SelectionStyle.SINGLE);
    grid.addRecordClickHandler(new RecordClickHandler() {
    public void onRecordClick(RecordClickEvent event) {
    DSRecord record = (DSRecord) event.getRecord();
    bindComponents(record.getDsName());
    }
    });
    // grid.draw();


    items = new SelectItem();
    items.setName("SelectedItems");
    items.setTitle("SelectedItems");
    items.setPickListWidth(210);
    items.setValueField("itemName");
    items.setDefaultToFirstOption(true);
    items.setAllowEmptyValue(false);
    items.setAutoFetchData(true);
    items.setOptionDataSource(DataSource.get("supplyItem"));

    HLayout layout= new HLayout();
    DynamicForm form = new DynamicForm();
    // form.set
    items.setLeft(20);
    items.setTop(75);

    form.setItems(items);
    layout.addMember(grid);

    layout.addMember( form );

    layout.setWidth(800);
    layout.draw();

    }

    private void bindComponents(String dsName) {
    DataSource ds = DataSource.get(dsName);
    items.setOptionDataSource(ds);
    if(dsName.equalsIgnoreCase("animals"))
    items.setValueField("scientificName");
    else if(dsName.equalsIgnoreCase("supplyItem"))
    items.setValueField("itemName");
    items.setDefaultToFirstOption(true);

    let me know whats
    }
    }

    let me know whats going wrong here.
    -Vinod
    Emailid: vinod.narayankar@gmail.com or vinod.narayankar@sabre.com
Working...
X