1. #1
    Sencha User
    Join Date
    Apr 2011
    Posts
    28
    Vote Rating
    0
    altmayer is on a distinguished road

      0  

    Default Correct handling of ComboBox.preProcessValue and postProcessValue

    Correct handling of ComboBox.preProcessValue and postProcessValue


    Hi,

    This is maybe something similar to another thread I have posted, but it is more connected with the above mentioned methods.

    since I have found only examples with SIMPLEComboBox so far, I wanted to ask how to implement preProcessValue and postProcessValue correctly in a normal ComboBox. I am using a ComboBox instead of a SimpleComboBox because I need <Key, Value> pairs in the list.

    Here is how I create my ComboBox and CellEditor:

    Code:
    ColumnConfig column = new ColumnConfig( UserListData.LANGUAGE_DISPLAYTEXT, "Language", 275 );
    final ComboBox<LanguageData> combo = new ComboBox<LanguageData>();
    combo.setValueField( LanguageData.LOCALE );
    combo.setDisplayField( LanguageData.DISPLAYTEXT );
    combo.setAllowBlank( false );
    combo.setEditable( false );
    CellEditor editor = new CellEditor(combo) {
          @Override
          public Object preProcessValue(Object value) {
            Object result = null;
            if( value != null ) {
              LanguageData language = new LanguageData();
              language.set(LanguageData.LOCALE, "");
              language.set(LanguageData.DISPLAYTEXT, value);
              result = language;
              //result = ( ( ModelData )value ).get( LanguageData.LOCALE );
            }
            return result;
          }
          
          @Override
          public Object postProcessValue(Object value) {
            Object result = null;
            if( value != null ) {
              result = ( ( ModelData )value ).get( LanguageData.DISPLAYTEXT );
            }
            return result;
          }
        };
    
    column.setEditor( editor );
    column.setMenuDisabled( true );
    columnConfigs.add( column );
    You see, the combobox has a model of type LanguageData. The store for the combobox is set at sometime when the form is shown where to fill in some data.
    The grid in which the combobox is used has another model data type of course (UserListData).

    Now, with the above code in pre/postProcessValue following things are working (besides I am using a RowEditor for editing):
    - no excpetions thrown when clicking a row, especially no null pointer exceptions and type conversion problems
    - Display of the value in the cell is correct after saving the data

    Not working:
    - when clicking on a row that has already been edited, there is only one item in the dropdown list: the value that has been saved before

    Thanks in advance!

  2. #2
    Software Architect
    Join Date
    Sep 2007
    Posts
    13,966
    Vote Rating
    130
    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


    Not working:
    - when clicking on a row that has already been edited, there is only one item in the dropdown list: the value that has been saved before
    Code:
    combo.setTriggerAction(TriggerAction.ALL);

  3. #3
    Sencha User
    Join Date
    Apr 2011
    Posts
    28
    Vote Rating
    0
    altmayer is on a distinguished road

      0  

    Default


    Quote Originally Posted by sven View Post
    Code:
    combo.setTriggerAction(TriggerAction.ALL);
    Yes, you are right. For some dumb reason, I had the trigger action set in my factory class that creates combo boxes, but not at the place where I created the combobox by hand. Thanks very much.

    To make a further comment about my current solution for combobox preselection and multilanguage solution:
    - I use the key field from the grid store for my language column now, not the display text
    - I completely leave the preSelectValue and postSelectValue as they are (no overrides)
    - to be able to display the display text of the language instead of the key value (ISO locale) in grids which have the same store, but are NOT editable, I just use a different GridCellRenderer that gets the value from the display field instead of the locale field

    Code:
    column.setRenderer( new GridCellRenderer<UserListData>() {
          @Override
          public Object render( UserListData model,
                                String property,
                                ColumnData config,
                                int rowIndex,
                                int colIndex,
                                ListStore<UserListData> store,
                                Grid<UserListData> grid )
          {
            return model.getLanguageDisplaytext();
          }
        });
    Anyway, it would be nice if ColumnConfig had the possibility to set a display field just like the combobox has.

  4. #4
    Sencha User
    Join Date
    Apr 2011
    Posts
    28
    Vote Rating
    0
    altmayer is on a distinguished road

      0  

    Default Updated info

    Updated info


    I wanted to add that this problem haunted me again.

    Because there were several different cases in which edtor values could be filled, in some cases I got class cast exceptions when I clicked a row with a language column. The reason was that when the first time the grid was filled with data, the locale string was the value parameter in the preProcessValue. Another time it was LanguageData which is derived from BaseModelData.

    To fix this, I did the following (I hope this works for all cases of data in a cell editor combobox):
    Code:
    @Override
        public Object preProcessValue( Object value ) {
          Object result = null;
          if( value != null ) {
            result = getModelValueFromComboStore( combo.getValueField(), value );
          }
          return result;
        }
    
        private Object getModelValueFromComboStore( String key, Object value ) {
          Object modelValueToMatch;
          if( value instanceof BaseModelData ) {
            modelValueToMatch = ( ( BaseModelData )value ).get( key );
          } else {
            modelValueToMatch = value;
          }
          return combo.getStore().findModel( key, modelValueToMatch );
        }

  5. #5
    Sencha User
    Join Date
    Oct 2011
    Posts
    10
    Vote Rating
    0
    raj_s37 is an unknown quantity at this point

      0  

    Default how to handle to retun list

    how to handle to retun list


    Please let me know how to handle the preProcessValue() in order to return list of selected values

    the case is i have more rows in which i am selecting different values,on selection of values,the values are getting retained for other rows also.please help me

Similar Threads

  1. Correct exception handling with JSON and Dataproxy
    By Fredde in forum Ext 3.x: Help & Discussion
    Replies: 1
    Last Post: 29 Mar 2010, 5:27 PM
  2. Replies: 1
    Last Post: 1 Apr 2009, 9:38 AM

Thread Participants: 2

film izle

hd film izle

film sitesi

takipci kazanma sitesi

takipci kazanma sitesi

güzel olan herşey

takipci alma sitesi

komik eğlenceli videolar