example to override getValueFieldProperties FilterBuilder - smartgwt

I want to override getValueFieldProperties for FilterBuilde.
My requirement is for some specific type of field I want to show selection, for Value field instead of simple text box.
I have visited following:
http://code.google.com/p/smartgwt/source/browse/tags/2.5/main/src/com/smartgwt/client/widgets/form/FilterBuilder.java?r=1796
thanks.

I found the solution for the requirement requirement is, for some specific type of field, I want to show selection, for Value field instead of simple text box.
for (DataSourceField field : dataSource.getFields()) {
String type = field.getAttribute("serverType");
if (type!=null && type.equals("SPECIFIC_TYPE")) {
TreeMap<String, String> map = new TreeMap<String, String>();
map.put("1", "value 1");
map.put("2", "value 2");
field.setValueMap(map);
}
}

Related

html.dropdownlistfor bind selected value to one column, set another column to the selected Text

I'm fairly new to mvc and razor views.
I have a DropDownListFor that successfully is populated with a list of values and text from a data table.
I also am successfully binding the selected value to a data column in my data model.
However, the database that I'm working with is not normalized and I have need to taking the Text from the selected item, and binding that to another field in my data model.
How hard is it to do this?
You have several options:
1. Call the database to get text after submit
public ActionResult Submit(int dropDownListId)
{
var text = string.Empty;
var dataItem = this._dbContext.SomeTableData.SingleOrDefault(m => m.Id == dropDownListId);
if (dataItem != null)
{
text = dataItem.Title;
}
// continue
}
2. Adjust the drop down list value and parse the value in controller/business layer:
If you're using the default DropDownListFor HtmlHelper your data source is type of IEnumerable<SelectListItem> so while you're building your Model class you're going to pass it to the view, do something like this:
//get data from database
var dataSource = this_dbContext.SomeTableData.Select(m => new SelectListItem()
{
Value = string.Format("{0}|{1}", m.Id, m.Title),
Text = m.Title
}
And after you submit data parse the value:
public ActionResult Submit(string dropDownListValue) {
string[] values = dropDownListValue.Split('|');
// values[0] = value
// values[1] = text
}
3. Add hidden field to the view and use JavaScript to store the text
$('#dropDownListId').on('change', function () {
var text = $(this).find('option:selected').text();
$('#dropDownListText').val(text); // hidden field
});
and collect the value after submit:
public ActionResult Submit(int dropDownListId, string dropDownListText)
{
//logic
}

Access value enumeration field fom content part in Editor Method Orchard

I want to access the selectedvalue (enumeration field) in content part when click submit save button in widget administrator. How I can do that in Editor Method?
If you know the name of the ContentPart that has that field, you can do it like this:
(dynamic)contentItem.ContentPartName.FieldName.SelectedValue
But if you don't know the name of the ContentPart, you can first use this to get all the fields of the content item at runtime:
using System.Runtime.CompilerServices;
using Microsoft.CSharp.RuntimeBinder;
// get all the fields from the contentItem without knowing part name
var callSite = CallSite<Func<CallSite, object, object>>
.Create(Binder.GetMember(0, contentItem.ContentType,
((dynamic)contentItem).GetType(), new[] { CSharpArgumentInfo.Create(0, null) }));
var contentItemFields = ((callSite.Target(callSite, ((dynamic)contentItem))).Fields) as List<ContentField>;
Having the list of fields, you now can search for the EnumerationField that you want, and get the selected value:
var yourField = (contentItemFields.FirstOrDefault(f => f.name == "YourField")) as EnumerationField;
var selectedValue = yourField.SelectedValue;

JSF2 internationalization example

Taking as a start point the JSF2 internationalization example of this link:
http://www.mkyong.com/jsf2/jsf-2-internationalization-example/
I want this example to display the language of the combos in the actual language selected.
Could somebody point me how this can be done?
Thanks!
It's just a matter of setting the proper labels in the static variable countries:
static {
countries = new LinkedHashMap<String,Object>();
countries.put("English", Locale.ENGLISH); //label, value
countries.put("Deutsch", Locale.GERMAN);
countries.put("Français", Locale.FRENCH);
// ... fill in with additional languages/locales as needed
}
You can get a bigger list of language names in their original language here: http://www.omniglot.com/language/names.htm
UPDATE: According to OP's comment, he needs the language names translated to every language. For that, one could come up with a solution simply making a map of language maps (that's quite a few maps), like this:
// set a default value for localeCode
private String localeCode = Locale.ENGLISH.toString();
// ...
static {
countries = new LinkedHashMap<Object, <String,Object>>();
englishCountries = new LinkedHashMap<String,Object>();
englishCountries.put("English", Locale.ENGLISH); //label, value
englishCountries.put("German", Locale.GERMAN);
englishCountries.put("French", Locale.FRENCH);
countries.put(Locale.ENGLISH, englishCountries);
germanCountries = new LinkedHashMap<String,Object>();
germanCountries.put("Englisch", Locale.ENGLISH);
germanCountries.put("Deutsch", Locale.GERMAN);
germanCountries.put("Französisch", Locale.FRENCH);
countries.put(Locale.GERMAN, germanCountries);
frenchCountries = new LinkedHashMap<String,Object>();
frenchCountries.put("Anglais", Locale.ENGLISH);
frenchCountries.put("Allemand", Locale.GERMAN);
frenchCountries.put("Français", Locale.FRENCH);
countries.put(Locale.FRENCH, frenchCountries);
// ... fill in with additional languages/locales as needed
}
public Map<Object, <String,Object>> getCountriesInMap() {
return countries;
}
// adapted value change listener from original:
public void countryLocaleCodeChanged(ValueChangeEvent e){
String newLocaleValue = e.getNewValue().toString();
//loop country map to compare the locale code
for (Object key : countries.keySet()) {
if (key.toString().equals(newLocaleValue)) {
FacesContext.getCurrentInstance().getViewRoot()
.setLocale((Locale) key);
}
}
}
and then you would choose the proper map to be used for the selectItems, with something like this:
<h:selectOneMenu value="#{language.localeCode}" onchange="submit()"
valueChangeListener="#{language.countryLocaleCodeChanged}">
<f:selectItems value="#{language.countriesInMap[language.localeCode]}" />
</h:selectOneMenu>
Note: Don't forget to set a default value for language.localeCode, or the dropdown won't show any options
Please note, though, that this is probably NOT a good idea for usability, since a user who chooses a foreign language by mistake may have a hard time to get back to a known language for her (that's why it's a good practice to make the lists have the language names in each own language).

vaadin : multiple links in one field on the table

I want to ask about the UI of the vaadin, which is Table.
If I used this component, then I have to create a field using this command:
userTable.addContainerProperty("Status", String.class, "Active");
If I want to create link into this field, then I have to do like this:
userTable.addContainerProperty("Action", Link.class, new Link("Remove", new ExternalResource("#")));
My question is, the example above, only display single link in one field which is REMOVE Link. I want to create two links in one field of that table. For example link for EDIT and DELETE below the "Action" field, how can I do that?
Use a generated column to add the components to each row. Create an Horizontal Layout and two Buttons as the content.
class ValueColumnGenerator implements Table.ColumnGenerator {
String format; /* Format string for the Double values. */
/**
* Creates double value column formatter with the given
* format string.
*/
public ValueColumnGenerator(String format) {
this.format = format;
}
/**
* Generates the cell containing the Double value.
* The column is irrelevant in this use case.
*/
public Component generateCell(Table source, Object itemId,
Object columnId) {
// Get the object stored in the cell as a property
Property prop =
source.getItem(itemId).getItemProperty(columnId);
if (prop.getType().equals(Double.class)) {
HorizontalLayout hbox = new HorizontalLayout()
hbox.addComponent(new Button("Status"))
hbox.addComponent(new Button("Remove"))
return hbox;
}
return null;
}
}
See Section 5.14.5 of the Book of Vaadin for more info:
https://vaadin.com/book/-/page/components.table.html
You can add this buttons to HorizontalLayout or any other container component. Then add this layout to the container property in your table.

How to get input text into the listfield of autocompletefield in blackberry?

I want to make something like the contact selection in OS 5.0 while composing message
For that I have made an autocompletefield with contacts as datasource. Now I want to add the user input, that is what he types into the drop down list which appears in autocompletefield so that if the contact is not available in the phonebook he can use the number.
Check this link: How to get the selected item as String in a Blackberry AutoCompleteField?
public void onSelect(Object selection, int type) {
super.onSelect(selection, type);
if(selection != null) {
String selectionAsString = getEditField().getText();
// Do whatever else you need to do with the String.
}
}

Resources