1. #1
    Sencha User
    Join Date
    Dec 2012
    Posts
    25
    Vote Rating
    1
    Answers
    1
    sanbenwu is on a distinguished road

      0  

    Default Answered: how to get the ComboBox value on the server

    Answered: how to get the ComboBox value on the server


    hi gays
    i want to get the value of the Combobox selected but i get the Label
    the client code is:
    public class AddRoleWindow extends MyWindow {
    private TreeLoader<RoleListWindow.JsonData> loader;
    private FramedPanel panel;
    private FormPanel form;
    private TextField name;
    private NumberField<Integer> id;
    private TextArea desc;
    private ComboBox state_role;
    private Integer addorEdit;
    private final String URL_ADD_ROLE = Const.SERVER + "role!showEdit.do";
    private final String URL_CHECK_ROLE = Const.SERVER + "role!check.do";


    @Override
    public String getAppName() {
    return "addRole";
    }


    @Override
    public boolean isShortCut() {
    return super.isShortCut();
    }


    public void setName(String name) {
    this.name.setValue(name);
    }


    public void setAddorEdit(Integer addorEdit) {
    this.addorEdit = addorEdit;
    }


    public void setId(Integer id) {
    this.id.setValue(id);
    }


    public void setDesc(String desc) {
    this.desc.setValue(desc);
    }


    public void setState(Integer state) {
    state_role.setTriggerAction(ComboBoxCell.TriggerAction.ALL);
    Iterator it = state_role.getStore().getAll().iterator();
    while (it.hasNext()) {
    State s = (State) it.next();
    if (state.equals(s.getId())){
    this.state_role.setValue(s);
    }


    }
    }


    public AddRoleWindow() {


    init();
    }


    public TreeLoader<RoleListWindow.JsonData> getLoader() {
    return loader;
    }


    public void setLoader(TreeLoader<RoleListWindow.JsonData> loader) {
    this.loader = loader;
    }


    @Override
    protected void onLoad() {


    }


    private void init() {


    this.name = createName();
    this.id = createId();
    this.state_role = createComboBox();
    this.desc = createDesc();
    this.form = createForm();
    if (null == panel) {
    panel = new FramedPanel();
    panel.setHeaderVisible(false);
    panel.setButtonAlign(BoxLayoutContainer.BoxLayoutPack.CENTER);
    panel.add(form);
    panel.getElement().setMargins(0);
    final TextButton button = new TextButton("submit");
    panel.addButton(button);

    button.addSelectHandler(new SelectEvent.SelectHandler() {
    @Override
    public void onSelect(SelectEvent event) {
    form.submit();
    }
    });
    form.addSubmitCompleteHandler(new SubmitCompleteEvent.SubmitCompleteHandler() {
    @Override
    public void onSubmitComplete(SubmitCompleteEvent event) {
    String result = event.getResults();
    if (result.indexOf("success") > -1)
    new AlertMessageBox(result, "success").show();


    else
    new AlertMessageBox("fail", result).show();
    button.setEnabled(true);
    /*loader.load();*/
    }
    }
    );
    this.add(panel);


    this.setHeadingText(addorEdit==null||addorEdit.intValue()==0?"add role":"edit role");
    this.setHeaderVisible(true);
    this.setPixelSize(350, 200);
    this.setMaximizable(true);
    this.setMinimizable(true);
    }
    }


    private TextField createName() {
    name = new TextField();
    name.setWidth(200);
    name.setAllowBlank(false);
    name.setName("name");
    return name;
    }


    private NumberField<Integer> createId() {
    id = new NumberField(new NumberPropertyEditor.IntegerPropertyEditor());
    id.setWidth(200);
    id.setName("id");
    id.setVisible(false);


    return id;
    }


    private TextArea createDesc() {
    desc = new TextArea();
    desc.setWidth(200);
    desc.setHeight(50);
    desc.setAllowBlank(true);
    desc.setName("desc");


    return desc;
    }




    private ComboBox createComboBox() {
    StateProperties prop = GWT.create(StateProperties.class);


    ListStore<State> store = new ListStore<State>(prop.id());
    List<State> list = new ArrayList<State>();
    list.add(new State(0, "NO"));
    list.add(new State(1, "YES"));
    store.addAll(list);
    state_role = new ComboBox<State>(store, prop.name());
    state_role.setWidth(200);
    state_role.setTypeAhead(true);
    // state_role.getListView().getSelectionModel().setSelectionMode(Style.SelectionMode.MULTI);


    state_role.setForceSelection(true);
    state_role.setName("state");




    // state_role.select(1);


    // state_role.getStore().get(1) ;
    return state_role;
    }


    private FormPanel createForm() {
    if (null == form)
    form = new FormPanel();
    VerticalLayoutContainer p = new VerticalLayoutContainer();
    form.setAction(URL_ADD_ROLE);
    form.setEncoding(FormPanel.Encoding.MULTIPART);
    form.setMethod(FormPanel.Method.POST);


    p.setStyleName("text");
    p.add(id);
    p.add(new FieldLabel(name, "NAME"));
    p.add(new FieldLabel(state_role, "STATE"));
    p.add(new FieldLabel(desc, "DESCRIPT"));
    /*p.setWidth(300);
    p.setHeight(250);*/
    // p.setPixelSize(300, 250);
    form.add(p);
    return form;
    }


    interface StateProperties extends PropertyAccess<State> {
    ModelKeyProvider<State> id();


    LabelProvider<State> name();
    }


    class State {
    private Integer id;
    private String name;


    State(Integer id, String name) {
    this.id = id;
    this.name = name;
    }


    public Integer getId() {
    return id;
    }


    public void setId(Integer id) {
    this.id = id;
    }


    public String getName() {
    return name;
    }


    public void setName(String name) {
    this.name = name;
    }
    }
    }
    and i selected the "no" on the server the value is no ,did't the 0
    how to do get the "0" not the Label value "no" thanks for you tell me the answer.

  2. You didn't explain how you are currently calling the value. Whenever I need to get the value of a combobox I use:

    combobox.getCurrentValue();

  3. #2
    Sencha User
    Join Date
    May 2011
    Posts
    47
    Vote Rating
    0
    Answers
    2
    nmb1106 is on a distinguished road

      0  

    Default


    You didn't explain how you are currently calling the value. Whenever I need to get the value of a combobox I use:

    combobox.getCurrentValue();

Thread Participants: 1