PDA

View Full Version : combobox - getValue



diegolovison
25 May 2010, 11:30 AM
User


public class User extends BeanModel {

public User(final Integer id, final String name) {
set("id", id);
set("name", name);
}

public String getName() {
return get("name");
}

}


MyTestClass


public class MyTestClass implements EntryPoint {

public void onModuleLoad() {

final User user1 = new User(1, "user 1");
final User user2 = new User(1, "user 2");
final User user3 = new User(1, "user 3");

final ListStore<User> store = new ListStore<User>();
store.add(user1);
store.add(user2);
store.add(user3);

final ComboBox<User> combo = new ComboBox<User>();
combo.setStore(store);
combo.setDisplayField("name");
combo.setValue(user1);

final Button btn = new Button("get value", new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected(final ButtonEvent ce) {
if (combo.getValue() != null) {
Window.alert(combo.getValue().getName());
} else {
Window.alert("null");
}
}
});

RootPanel.get().add(combo);
RootPanel.get().add(btn);
}
}


TestCase 1
1 - Click in the button "get value" will return "user 1"
2 - click in the trigger button and change to "user 2"
3 - click in the button "get value" will return "user 2"
4 - select all text and press delete
5 - click in the button "get value" will return "null"
6 - this test case its OK

TestCase 2
1 - Click in the button "get value" will return "user 1"
2 - select all text and press delete
3 - click in the button "get value" will return "user 1"
4 - this test case its NOT OK, should be return "null"... this problem occurs because in getValue of the ComboBoxClass have



if (!initialized) {
return value;
}


I believe that if have this before the validation above, will correct the problem..



String rw = getRawValue();

if (rw == null || rw.length() == 0) {
return null
}

if (!initialized) {
return value;
}

diegolovison
25 May 2010, 11:35 AM
but with my solution have one problem...

if the user type "xuleta" and dont press DELETE will return "user 1"...

diegolovison
25 May 2010, 11:43 AM
@Override
public D getValue() {

final String v = getRawValue();
if (emptyText != null && v.equals(emptyText)) {
return null;
}
if (v == null || v.equals("")) {
return null;
}

return super.getValue();
}


but this code dont resolve the problem above

sven
25 May 2010, 1:23 PM
This is not a bug.

You need to set lazyRender to false.

diegolovison
25 May 2010, 1:37 PM
thanks sven.. I believe that will work (I will test tomorrow)...

diegolovison
26 Aug 2010, 10:58 AM
if I set lazyRender to false dont solve the problem....

sven
26 Aug 2010, 11:08 AM
I just tested this against 2.2 RC1 and it works without any problems

diegolovison
26 Aug 2010, 11:10 AM
I'm using this version and for me dont work...

diegolovison
26 Aug 2010, 11:11 AM
sorry... I'm using the wrong thread