Announcement

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

    SelectItem (setselected item and getselected item)

    hi all,
    how i can set selected and get selected item ?
    i found example how to get selected item into on change event, but i don't need this, i want to get selected item on submit button click, also i want to set selected item when my dialog opened, and selectitem component is already filled.

    I want to get selected ID not text value.


    Any Idea ?


    ______________________
    Regards,
    Paata Lominadze.

    #2
    is this so difficult ?

    Comment


      #3
      Code:
          btnSubmit.addClickHandler(new ClickHandler() {
      
            public void onClick(ClickEvent event) {
              selectItem.getSelectedRecord().getAttributeAsInt("id");
            }
          });
      is this what you need?

      Comment


        #4
        hi,
        Thank you very much for your post.
        I'm coming from "java swing world" and maybe I'm on a wrong way.
        My code snippets:
        Code:
        LinkedHashMap<String, String> map = new LinkedHashMap<String, String>();
        map.put("key1"," "Value 1 ");
        map.put("key2"," "Value 2 ");
        map.put("key3"," "Value 3 ");
        map.put("key4"," "Value 4 ");
        map.put("key5"," "Value 5 ");
        .................... some other code
        DynamicForm form = new DynamicForm();
        ................... some other code
        ComboBoxItem cbItem = new ComboBoxItem();
        cbItem.setRequired(true);
        cbItem.setTitle("Select : ");
        cbItem.setTitleAlign(Alignment.LEFT);
        // fill
        cbItem.setValueMap(map);
        
        ................... some other code
        Button btnSubmit.addClickHandler(new ClickHandler() {
              public void onClick(ClickEvent event) {
                 // i choose "Value 3" from combobox
                 // how i can get "Key3" ????
              }
        });
        how i understand it is impossible to put Objects into combobox. it must be only String values.


        and what about setting selection:
        in my example i have 5 values into combobox.
        now i want to selected 3rd element selected. how ?

        Comment


          #5
          This it appears to be working:

          Code:
              LinkedHashMap<String, String> map = new LinkedHashMap<String, String>();
              map.put("key1", "Value 1 ");
              map.put("key2", "Value 2 ");
              map.put("key3", "Value 3 ");
              map.put("key4", "Value 4 ");
              map.put("key5", "Value 5 ");
          
              DynamicForm form = new DynamicForm();
          
              final ComboBoxItem cbItem = new ComboBoxItem();
              cbItem.setRequired(true);
              cbItem.setTitle("Select : ");
              cbItem.setTitleAlign(com.smartgwt.client.types.Alignment.LEFT);
          
              cbItem.setValueMap(map);
          
              IButton btnSubmit = new IButton("sumbmit");
              btnSubmit.addClickHandler(new ClickHandler() {
                public void onClick(ClickEvent event) {
                  com.google.gwt.user.client.Window.alert((String)cbItem.getValue());
                  cbItem.setValue("key5");
                  com.google.gwt.user.client.Window.alert((String)cbItem.getValue());
                }
              });
          
              form.setFields(cbItem);
          
              HLayout hLayout = new HLayout();
              hLayout.addMember(form);
              hLayout.addMember(btnSubmit);
          
              hLayout.draw();

          Comment

          Working...
          X