use of com.manydesigns.elements.fields.search.SelectSearchField in project Portofino by ManyDesigns.
the class SearchFormTest method testForm2a.
// Lettura multipla da request con checkbox
public void testForm2a() {
SelectSearchField field = (SelectSearchField) form.get(4);
String[] field5Values = { "1", "2" };
req.setParameter("field5", field5Values);
field.readFromRequest(req);
Object[] value = (Object[]) field.getSelectionModel().getValue(0);
assertEquals("1", (String) value[0]);
field.toXhtml(buffer);
String result = writer.toString();
assertEquals("<div class=\"form-group\"><label for=\"field5\" class=\"control-label\">Field5</label><div class=\"form-control checkbox\"><input id=\"field5_0\" type=\"checkbox\" name=\"field5\" value=\"1\" checked=\"checked\" /><label for=\"field5_0\">a</label></div><div class=\"form-control checkbox\"><input id=\"field5_1\" type=\"checkbox\" name=\"field5\" value=\"2\" checked=\"checked\" /><label for=\"field5_1\">b</label></div></div>", result);
StringBuilder sb = new StringBuilder();
field.toSearchString(sb, "UTF-8");
result = sb.toString();
assertEquals("field5=1,field5=2", result);
}
use of com.manydesigns.elements.fields.search.SelectSearchField in project Portofino by ManyDesigns.
the class SearchFormTest method testForm8.
public void testForm8() {
SelectSearchField field = (SelectSearchField) form.get(4);
// Controllo l'html prodotto
field.toXhtml(buffer);
writer.flush();
String result = writer.toString();
assertEquals("<div class=\"form-group\"><label for=\"field5\" class=\"control-label\">Field5</label><div class=\"form-control checkbox\"><input id=\"field5_0\" type=\"checkbox\" name=\"field5\" value=\"1\" /><label for=\"field5_0\">a</label></div><div class=\"form-control checkbox\"><input id=\"field5_1\" type=\"checkbox\" name=\"field5\" value=\"2\" /><label for=\"field5_1\">b</label></div></div>", result);
}
use of com.manydesigns.elements.fields.search.SelectSearchField in project Portofino by ManyDesigns.
the class SearchFormBuilder method build.
// **************************************************************************
// Building
// **************************************************************************
public SearchForm build() {
logger.debug("build");
SearchForm searchForm = new SearchForm();
FieldsManager manager = FieldsManager.getManager();
if (propertyAccessors == null) {
configReflectiveFields();
}
Map<String, SearchField> fieldMap = new HashMap<String, SearchField>();
for (PropertyAccessor propertyAccessor : propertyAccessors) {
SearchField field = null;
String fieldName = propertyAccessor.getName();
for (Map.Entry<String[], SelectionProvider> current : selectionProviders.entrySet()) {
String[] fieldNames = current.getKey();
int index = ArrayUtils.indexOf(fieldNames, fieldName);
if (index >= 0) {
field = new SelectSearchField(propertyAccessor, current.getValue(), prefix);
break;
}
}
if (field == null) {
field = manager.tryToInstantiateSearchField(classAccessor, propertyAccessor, prefix);
}
if (field == null) {
logger.warn("Cannot instantiate field for property {}", propertyAccessor);
continue;
}
fieldMap.put(fieldName, field);
searchForm.add(field);
}
// handle cascaded select fields
for (Map.Entry<String[], SelectionProvider> current : selectionProviders.entrySet()) {
String[] fieldNames = current.getKey();
SelectionProvider selectionProvider = current.getValue();
SelectionModel selectionModel = selectionProvider.createSelectionModel();
SelectSearchField previousField = null;
for (int i = 0; i < fieldNames.length; i++) {
SelectSearchField selectSearchField = (SelectSearchField) fieldMap.get(fieldNames[i]);
if (selectSearchField == null) {
previousField = null;
continue;
}
selectSearchField.setSelectionModel(selectionModel);
selectSearchField.setSelectionModelIndex(i);
if (previousField != null) {
selectSearchField.setPreviousSelectField(previousField);
previousField.setNextSelectField(selectSearchField);
}
previousField = selectSearchField;
}
}
return searchForm;
}
Aggregations