Smartgwt selectitem key value issue - smartgwt

I have a SelectItem which I fill through a Map that has this combo is within a listgridfield, so good up there, but when I select any item in the combobox instead of get the description or value of the map puts the key in the listgridfield.
How I can do to make me set the value instead of key? now I tried to do with AddChangeHandler but has not worked.
I got the next code:
final ListGridField measureField = new ListGridField(CdmsConstants.MEASURE_ABB, CdmsConstants.CMB_MEASURE_TITULO, 100);
final SelectItem measureComboBox = new SelectItem();
measureComboBox.setDefaultToFirstOption(false);
measureComboBox.setName(CdmsConstants.MEASURE_ABB);
measureComboBox.setTitle(CdmsConstants.CMB_MEASURE_TITULO);
measureComboBox.setDefaultValues(CdmsConstants.CMB_DEFAULT_VALUE);
measureComboBox.setType("comboBox");
measureComboBox.setVisible(true);
measureComboBox.setValueMap(result);
measureComboBox.setValidateOnExit(true);
measureField.setEditorType(measureComboBox);
In the measureComboBox When i put the variable result (that is a Map) and click to any item of the combo the value that shows into the combo box is the key of the linckedhashmap and no the value of the item... how can i make to change this?
Thanks a lot.

If you use a datasource instead of LinkedHashMap, then you can use setValueField method of SelectItem instance. but in this case MAY you can use setValueFormatter method of your SelectItem object.

I had the same/similar problem, my solution that can be seen here ListGrid.setEditorCustomizer in SmartGWT was to use a datasource for the SelectItem and then implemented my own CellFormatter

Related

vaadin, allow new typed item in combobox

I've faced with the issue with Vaasin's Combobox. I'd like to allow the user be able as select existed item from the list same provide his own value typing in the text field. I thought that it has to be easy, but... What I have now is
ComboBox roles = new ComboBox();
roles.setInputPrompt("Select Role");
roles.addItems(userService.getAllRoles());
roles.setImmediate(true);
roles.setNullSelectionAllowed(false);
roles.setNewItemsAllowed(true);
formLayout.addComponent(roles);
Here I've found that setNewItemsAllowed allows such behavior, but for some reason it doesn't work for me. When I start typing some new value I can see an empty drop-down and when I select another field the value in checkbox reverts to prompt text.
It is not enough to allow new items in the ComboBox.
You must alos set the new item handler, until you do so, the ComboBox has no way to know what a new item should look like.
roles.setNewItemHandler(....your handler....);
Example code and the Docu for it.

SelectItem with property multiple select

I´m using the SelectItem component with configuration:
private SelectItem nElementsCombo;
nElementsCombo = new SelectItem();
nElementsCombo.setMultiple(true);
nElementsCombo.setMultipleValueSeparator("|");
In the combo the elements selected are shown item_selected_1|item_selected_2|item_selected_3
but when I do:
nElementsCombo.getValueAsString()
Return item_selected_1,item_selected_2,item_selected_3 and I´d like item_selected_1|item_selected_2|item_selected_3
How can I solve this?
from the javadoc :If this item is displaying multiple values, this property will be the string that separates those values for display purposes. Display purpose
I don't catch it, can you replace in your returned string the comma by the pipe ..... !!!
As per Alain's answer, MultipleValueSeparator is only for display purpose.
Means, when you select multiple values from picklist & then when the picklist is hidden on blur (focus lost) of multi select item, the selected values are displayed as a string separated by comma(default). This display can be changed by MultipleValueSeparator. But not the one you get by multiSelectItem.getValueAsString().
Also I don't think, there's any provision in SmartGWT API which fulfills your requirement, as of now.

ComBox filling SmartGWT

I have the requirement to enter the data into comboBox after getting the text from TextBox by pressing the add button. How can i get it done in SmartGWT?
I believe you'll want to start by associating a DataSource with your ComboBoxItem. After that, be sure to call both setValueField(...) and setDisplayField(...) on the combo box. You should start seeing fetch requests get sent when the combo box is instantiated, and the results of the fetch should display in the combo box.
If its not a ComboBox bounded to a datasource its done like this:
Map<String, String> valueMap= new LinkedHashMap<String, String>();
valueMap.put("key","description");
comboBoxItem.setValueMap(valueMap);

How to get the selected text from a system.web.mvc.selectlist

I have a system.web.mvc.selectlist when I use .selectedvalue it gives me the value as expected however I use an int ID as the value and would like to get the display text instead.
Update
I've created a selectlist and I'd like to retrieve the selected text on the next line of code. I.e.
SelectList sl = new SelectList(items, "id", "name", 10);
String txt= sl.selectedvalue.text;
That last line is where I am stuck. I'm looking to get the name field for the item with id 10. Ideally without looking up in the db as I want a generic function I can use on all select lists.
I don't think this is possible since the text isn't passed back to the server in a post, only the value is. I can think of two ways to get it though:
Query the database with the value to get the text.
Set the text in a hidden field on the client side before posting the
form. You can do this with jQuery for example.

Add empty value to a DropDownList in ASP.net MVC

I'm building a data entry interface and have successfully bound the columns that have reference tables for their data using DropDownList so the user selects from the pre-configured values.
My problem now is that I don't want the first value to be selected by default, I need to force the user to select a value from the list to avoid errors where they didn't pick that field and by default a value was assigned.
Is there a more elegant way of doing this than to add code to include an empty value at the top of the list after I get it from the database and before i pass it to the SelectList constructor in my controller class?
The Html helper function takes a 'first empty value' parameter as the third argument.
<%=Html.DropDownList("name",dataSource,"-please select item-")%>
You can also use this way:
dropdownlist.DataTextField = ds.Tables[0].Columns[0].Caption;
dropdownlist.DataValueField = ds.Tables[0].Columns[1].Caption;
dropdownlist.DataSource = ds;
dropdownlist.DataBind();
dropdownlist.Items.Insert(0, new ListItem("Select ...", string.Empty));

Resources