DaRkViDe
9 Dec 2010, 9:39 AM
Hi,
I've a problem with combobox containig Beans object!
All works fine except if i set a default value with .setValue(BEANOBJECT) loaded from db and the combos shows the correct value but when i call .getValue() without modify the selected value the combo returns null!
If i select another value all works correctly!
I used this method with combobox of content type <String> and when i call .getValue() all works fine!
Instead with beans the combos returns null if not modified...
I tryed with .getOriginalValue() method and this works but if i select a different vaule from the combo the returned value is the old wrong...
I thought about using a listener to set a boolean value if the combo where modified or not, and call the getValue() or .getOriginalValue() method but i hope that exist a better solution...
Thanks
Below some code...
RpcProxy<PagingLoadResult<EnteModel>> proxyEnte = new RpcProxy<PagingLoadResult<EnteModel>>() {
@Override
protected void load(Object loadConfig,
AsyncCallback<PagingLoadResult<EnteModel>> callback) {
bibliotecheService.getEntiPaginatiFilteredPerCombos(
(ModelData) loadConfig, callback);
}
};
ModelReader enteReader = new ModelReader();
final PagingLoader<PagingLoadResult<VoceUnicaModel>> enteLoader = new BasePagingLoader<PagingLoadResult<VoceUnicaModel>>(
proxyEnte, enteReader);
enteLoader.load();
final ListStore<EnteModel> listStoreEnte = new ListStore<EnteModel>(
enteLoader);
final ComboBox<EnteModel> denominazioneEnteField = new ComboBox<EnteModel>();
denominazioneEnteField.setWidth(400);
denominazioneEnteField.setDisplayField("denominazione");
denominazioneEnteField.setStore(listStoreEnte);
denominazioneEnteField.setFireChangeEventOnSetValue(true);
denominazioneEnteField.setEmptyText("Scegli una denominazione...");
denominazioneEnteField.setForceSelection(false);
denominazioneEnteField.setLazyRender(false);
denominazioneEnteField.setTriggerAction(TriggerAction.ALL);
denominazioneEnteField.setEditable(true);
denominazioneEnteField.setPageSize(10);
denominazioneEnteField.setTypeAhead(true);
denominazioneEnteField.setMinChars(1);
//HERE SET A DEFAULT VALUE
denominazioneEnteField.setValue(biblioteca.getEnte());
Button updateEnteAppartenenza = new Button("Crea l'ente di appartenenza");
updateEnteAppartenenza.addSelectionListener(new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected(ButtonEvent ce) {
final Listener<MessageBoxEvent> l = new Listener<MessageBoxEvent>() {
public void handleEvent(MessageBoxEvent ce) {
Button btn = ce.getButtonClicked();
if (btn.getText().equalsIgnoreCase("Si")) {
HashMap<String, Object> params = new HashMap<String, Object>();
//THIS METHOD RETURN A NULL VALUe: .getValue(BEAN) params.put("denominazione",denominazioneEnteField.getValue().getDenominazione());
params.put("enteTipologiaAmministrativa",tipologiaAmministrativaField.getValue());
params.put("stato",statoAppartenenzaField.getValue());
bibliotecheService.setEnte(biblioteca.getIdBiblio(),
params, new AsyncCallback<Void>() {
@Override
public void onFailure(Throwable caught) {
MessageBox m = new MessageBox();
m.setType(MessageBoxType.ALERT);
m.setTitle("ERRORE UPDATE");
m.setMessage("Errore durante l'aggiornamento!");
m.setIcon(MessageBox.ERROR);
m.show();
}
@Override
public void onSuccess(Void result) {
MessageBox
.info("ESITO UPDATE",
"Aggiornamento effettuato con successo!",
null)
.show();
fireReleoadbiblioDataEvent();
}
});
}
}
};
MessageBox
.confirm(
"UPDATE",
"La modifica verrĂ applicata al database! Continuare?",
l).show();
}
});
I've a problem with combobox containig Beans object!
All works fine except if i set a default value with .setValue(BEANOBJECT) loaded from db and the combos shows the correct value but when i call .getValue() without modify the selected value the combo returns null!
If i select another value all works correctly!
I used this method with combobox of content type <String> and when i call .getValue() all works fine!
Instead with beans the combos returns null if not modified...
I tryed with .getOriginalValue() method and this works but if i select a different vaule from the combo the returned value is the old wrong...
I thought about using a listener to set a boolean value if the combo where modified or not, and call the getValue() or .getOriginalValue() method but i hope that exist a better solution...
Thanks
Below some code...
RpcProxy<PagingLoadResult<EnteModel>> proxyEnte = new RpcProxy<PagingLoadResult<EnteModel>>() {
@Override
protected void load(Object loadConfig,
AsyncCallback<PagingLoadResult<EnteModel>> callback) {
bibliotecheService.getEntiPaginatiFilteredPerCombos(
(ModelData) loadConfig, callback);
}
};
ModelReader enteReader = new ModelReader();
final PagingLoader<PagingLoadResult<VoceUnicaModel>> enteLoader = new BasePagingLoader<PagingLoadResult<VoceUnicaModel>>(
proxyEnte, enteReader);
enteLoader.load();
final ListStore<EnteModel> listStoreEnte = new ListStore<EnteModel>(
enteLoader);
final ComboBox<EnteModel> denominazioneEnteField = new ComboBox<EnteModel>();
denominazioneEnteField.setWidth(400);
denominazioneEnteField.setDisplayField("denominazione");
denominazioneEnteField.setStore(listStoreEnte);
denominazioneEnteField.setFireChangeEventOnSetValue(true);
denominazioneEnteField.setEmptyText("Scegli una denominazione...");
denominazioneEnteField.setForceSelection(false);
denominazioneEnteField.setLazyRender(false);
denominazioneEnteField.setTriggerAction(TriggerAction.ALL);
denominazioneEnteField.setEditable(true);
denominazioneEnteField.setPageSize(10);
denominazioneEnteField.setTypeAhead(true);
denominazioneEnteField.setMinChars(1);
//HERE SET A DEFAULT VALUE
denominazioneEnteField.setValue(biblioteca.getEnte());
Button updateEnteAppartenenza = new Button("Crea l'ente di appartenenza");
updateEnteAppartenenza.addSelectionListener(new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected(ButtonEvent ce) {
final Listener<MessageBoxEvent> l = new Listener<MessageBoxEvent>() {
public void handleEvent(MessageBoxEvent ce) {
Button btn = ce.getButtonClicked();
if (btn.getText().equalsIgnoreCase("Si")) {
HashMap<String, Object> params = new HashMap<String, Object>();
//THIS METHOD RETURN A NULL VALUe: .getValue(BEAN) params.put("denominazione",denominazioneEnteField.getValue().getDenominazione());
params.put("enteTipologiaAmministrativa",tipologiaAmministrativaField.getValue());
params.put("stato",statoAppartenenzaField.getValue());
bibliotecheService.setEnte(biblioteca.getIdBiblio(),
params, new AsyncCallback<Void>() {
@Override
public void onFailure(Throwable caught) {
MessageBox m = new MessageBox();
m.setType(MessageBoxType.ALERT);
m.setTitle("ERRORE UPDATE");
m.setMessage("Errore durante l'aggiornamento!");
m.setIcon(MessageBox.ERROR);
m.show();
}
@Override
public void onSuccess(Void result) {
MessageBox
.info("ESITO UPDATE",
"Aggiornamento effettuato con successo!",
null)
.show();
fireReleoadbiblioDataEvent();
}
});
}
}
};
MessageBox
.confirm(
"UPDATE",
"La modifica verrĂ applicata al database! Continuare?",
l).show();
}
});