SelectItem with property multiple select - smartgwt

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.

Related

List / Repeater component for Vaadin

In my previous project, I've used BeanItemContainer and a Table with GeneratedColumns to simply display a custom component that displays a search result, like google. Title, date, content in a vertical fashion.
As horrible as it was (table) it worked.
Now I want to utilize Grid component for a new project, with the same objective.
The column will be generated and contain a custom component.
Will this work with Grid? is there something better, like a list or repeater component available? Any example of a single column with custom component?
It seems like Vaadin frowns on anything other than simple data or Button renderers.
Update
It looks like adding components don't work out of the box with Grid 7.5+
Also, Grid cells like to be only be fixed hight
ComponentRederer Add-on support cell components, however fix height is still an issue.
Sample code:
public class Result {
String title;
Date date;
URL url;
String description;
List<String> tags;
public Result (){}
}
BeanItemContainer<Result> resultContainer = fetchResults(searchTerm);
I also use a Lazy Container too, beanitem used for simplicity.
I then have a RecordResultComponent that constructs the layout of a single record result in the follow layout:
Title(link with Url)
Date
Description
tag1 tag2 tag3 ...
You can use a Grid alongwith a GeneratedPropertyContainer.
Then, you can use a HtmlRenderer on the custom column.
I hope it helps. :-)

Smartgwt selectitem key value issue

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

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.

String[] vs Integer[] in Struts2 action attribute

I am new t struts2. i built one page, that shows list of employees. I can seach the employes based on his name by applying filter criteria and click on find button. At the same time, i provided check box in the left side for each employee name for delete operation. for all checkboxes, i gave Integer[] attribute name which is declared in Custom Actionclass.deleteaction is working fine. But when i click Find button the action is not getting submitted. Then i changed Integer[] to String[] both functions are working fine. What will be the problem? is it something like, attributes should only be String type.
The cause of your problem is that the Struts2 checkbox sets a boolean property on the action class:
Struts 2 Form Tags: Checkbox
When you defined the checkboxes as an Integers, the framework couldn't covert the boolean to an Integer. However it was able to convert the boolean to Strings. If you check the results in your action class, you should see the String[] populated with "true" and "false".
In general Struts2 is pretty good at converting submitted form data to whatever object type you want. Check out the docs on type conversion for more info.

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