use of com.manydesigns.elements.options.DefaultSelectionProvider in project Portofino by ManyDesigns.
the class SelectSearchField method initializeModel.
private void initializeModel(PropertyAccessor accessor, SelectionProvider selectionProvider) {
Select annotation = accessor.getAnnotation(Select.class);
if (selectionProvider == null) {
if (annotation != null) {
Object[] values = annotation.values();
String[] labels = annotation.labels();
assert (values.length == labels.length);
DefaultSelectionProvider sp = new DefaultSelectionProvider(accessor.getName(), 1);
for (int i = 0; i < values.length; i++) {
sp.appendOption(values[i], labels[i], true);
}
selectionModel = sp.createSelectionModel();
displayMode = annotation.searchDisplayMode();
}
} else {
displayMode = selectionProvider.getSearchDisplayMode();
if (displayMode == null && annotation != null) {
displayMode = annotation.searchDisplayMode();
}
}
if (displayMode == null) {
displayMode = SearchDisplayMode.DROPDOWN;
}
selectionModelIndex = 0;
comboLabel = getText("elements.field.select.select", label);
notSetLabel = getText("elements.search.select.notset", label);
autocompleteId = id + AUTOCOMPLETE_SUFFIX;
autocompleteInputName = inputName + AUTOCOMPLETE_SUFFIX;
}
use of com.manydesigns.elements.options.DefaultSelectionProvider in project Portofino by ManyDesigns.
the class SearchFormTest method testForm10.
// testo il form builder aggiungendo un selection provider a cascata su field2
public void testForm10() {
DefaultSelectionProvider provider = new DefaultSelectionProvider("provider");
provider.appendOption("v1", "ll", true);
provider.appendOption("v2", "l2", true);
provider.appendOption("v3", "l3", true);
SearchFormBuilder builder = new SearchFormBuilder(AnnotatedBean3.class);
builder.configSelectionProvider(provider, "field2");
form = builder.build();
SelectSearchField field = (SelectSearchField) form.get(1);
// Controllo l'html prodotto
field.toXhtml(buffer);
writer.flush();
String result = writer.toString();
assertEquals("<div class=\"form-group\"><label for=\"field2\" class=\"control-label\">Field2</label><select id=\"field2\" name=\"field2\" class=\"form-control\"><option value=\"\" selected=\"selected\">-- Select field2 --</option><option value=\"__notset__\">-- Not set --</option><option value=\"v1\">ll</option><option value=\"v2\">l2</option><option value=\"v3\">l3</option></select></div>", result);
}
use of com.manydesigns.elements.options.DefaultSelectionProvider in project Portofino by ManyDesigns.
the class SearchFormTest method testForm5.
// testo il form builder aggiungendo un selection provider su field2
public void testForm5() {
DefaultSelectionProvider provider = new DefaultSelectionProvider("provider");
provider.appendRow("v1", "ll", true);
provider.appendRow("v2", "l2", true);
provider.appendRow("v3", "l3", true);
SearchFormBuilder builder = new SearchFormBuilder(AnnotatedBean3.class);
builder.configSelectionProvider(provider, "field2");
form = builder.build();
SelectSearchField field = (SelectSearchField) form.get(1);
// Controllo l'html prodotto
field.toXhtml(buffer);
writer.flush();
String result = writer.toString();
assertEquals("<div class=\"form-group\"><label for=\"field2\" class=\"control-label\">Field2</label><select id=\"field2\" name=\"field2\" class=\"form-control\"><option value=\"\" selected=\"selected\">-- Select field2 --</option><option value=\"__notset__\">-- Not set --</option><option value=\"v1\">ll</option><option value=\"v2\">l2</option><option value=\"v3\">l3</option></select></div>", result);
}
use of com.manydesigns.elements.options.DefaultSelectionProvider in project Portofino by ManyDesigns.
the class SelectFieldTest2 method setUp.
@Override
@BeforeMethod
public void setUp() throws Exception {
super.setUp();
selectionProvider = new DefaultSelectionProvider("selectionProvider", 2);
for (int i = 0; i < valuesArray.length; i++) {
selectionProvider.appendRow(valuesArray[i], labelsArray[i], true);
}
form = new FormBuilder(Bean.class).configSelectionProvider(selectionProvider, "p1", "p2").build();
FieldSet fieldSet = form.get(0);
selectField1 = (SelectField) fieldSet.get(0);
selectField2 = (SelectField) fieldSet.get(1);
selectionModel = selectField1.getSelectionModel();
}
use of com.manydesigns.elements.options.DefaultSelectionProvider in project Portofino by ManyDesigns.
the class SearchFormCascadeTest method setUp.
@Override
@BeforeMethod
public void setUp() throws Exception {
super.setUp();
selectionProvider = new DefaultSelectionProvider("selectionProvider", 2);
for (int i = 0; i < valuesArray.length; i++) {
selectionProvider.appendRow(valuesArray[i], labelsArray[i], true);
}
form = new SearchFormBuilder(SelectFieldTest2.Bean.class).configSelectionProvider(selectionProvider, "p1", "p2").build();
selectField1 = (SelectSearchField) form.get(0);
selectField2 = (SelectSearchField) form.get(1);
selectionModel = selectField1.getSelectionModel();
}
Aggregations