1. #1
    Sencha User
    Join Date
    Oct 2010
    Posts
    47
    Vote Rating
    0
    DaRkViDe is on a distinguished road

      0  

    Default ComboBox<Bean> .getvalue() method return null if not modified

    ComboBox<Bean> .getvalue() method return null if not modified


    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...

    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();
    					}
    				});

  2. #2
    Sencha User
    Join Date
    Sep 2007
    Posts
    13,971
    Vote Rating
    132
    sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light

      0  

    Default


    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!
    Is the model you set currently in the store of the combo? If you have paging, it could happen that is not in there.

  3. #3
    Sencha User
    Join Date
    Oct 2010
    Posts
    47
    Vote Rating
    0
    DaRkViDe is on a distinguished road

      0  

    Default


    Is the model you set currently in the store of the combo? If you have paging, it could happen that is not in there.
    in the drop down panel, combo can show only 10 items at time...all record in db are more then 2 hundred, certainly the defalut value set is not in the store...or is very difficult...

    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...
    is good-for-nothing iterate the store if in 99% it doesn't contain the default value cause of the pagination..
    In this case the above can be a solution?

  4. #4
    Sencha User
    Join Date
    Sep 2007
    Posts
    13,971
    Vote Rating
    132
    sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light

      0  

    Default


    Code:
     private class MyCombo<M extends ModelData> extends ComboBox<M> {
        @Override
        public M getValue() {
          if (value != null) {
            Object val = value.get(getDisplayField());
            if (getRawValue().equals(val != null ? val.toString() : null)) {
              return value;
            }
    
          }
          return super.getValue();
        }
      }
    Try this custom class. Should work for this usecase too

  5. #5
    Sencha User
    Join Date
    Oct 2010
    Posts
    47
    Vote Rating
    0
    DaRkViDe is on a distinguished road

      0  

    Default


    ok thanks

  6. #6
    Sencha User
    Join Date
    Sep 2007
    Posts
    13,971
    Vote Rating
    132
    sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light

      0  

    Default


    Please report back here if it works or not.

  7. #7
    Sencha User
    Join Date
    Oct 2010
    Posts
    47
    Vote Rating
    0
    DaRkViDe is on a distinguished road

      0  

    Default


    It works, thanks! I'm very grateful for your support sven!
    Thanks again..

Similar Threads

  1. Replies: 3
    Last Post: 3 Dec 2010, 11:33 PM
  2. [CLOSED] ComboBox getValue return null - rc1
    By fother in forum Ext GWT: Bugs (2.x)
    Replies: 4
    Last Post: 26 Jun 2009, 10:48 AM
  3. ComboBox.getValue return null after binding???
    By lichnost in forum Ext GWT: Help & Discussion (1.x)
    Replies: 13
    Last Post: 7 Jun 2009, 11:05 AM
  4. ComboBox getValue should return the real value, not the displayValue
    By Dumas in forum Ext 2.x: Help & Discussion
    Replies: 2
    Last Post: 8 Mar 2009, 11:40 PM

Thread Participants: 1