-
9 May 2011 3:40 AM #1
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:
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.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 );
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!
-
9 May 2011 3:52 AM #2
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 beforeCode:combo.setTriggerAction(TriggerAction.ALL);
-
9 May 2011 6:49 AM #3
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
Anyway, it would be nice if ColumnConfig had the possibility to set a display field just like the combobox has.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(); } });
-
23 May 2011 6:52 AM #4
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 ); }
-
30 Jan 2012 6:22 AM #5
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
-
Correct exception handling with JSON and Dataproxy
By Fredde in forum Ext 3.x: Help & DiscussionReplies: 1Last Post: 29 Mar 2010, 5:27 PM -
[FIXED] cancelEdit does not take preProcessValue into consideration
By thatone in forum Ext GWT: Bugs (1.x)Replies: 1Last Post: 1 Apr 2009, 9:38 AM


Reply With Quote