use of com.manydesigns.elements.reflection.PropertyAccessor in project Portofino by ManyDesigns.
the class SearchFormBuilder method configReflectiveFields.
public SearchFormBuilder configReflectiveFields() {
logger.debug("configReflectiveFields");
propertyAccessors = new ArrayList<>();
for (PropertyAccessor current : classAccessor.getProperties()) {
if (!isPropertyEnabled(current)) {
continue;
}
// check if field is searchable
Searchable searchableAnnotation = current.getAnnotation(Searchable.class);
if (searchableAnnotation != null && !searchableAnnotation.value()) {
logger.debug("Skipping non-searchable field: {}", current.getName());
continue;
}
propertyAccessors.add(current);
}
return this;
}
use of com.manydesigns.elements.reflection.PropertyAccessor in project Portofino by ManyDesigns.
the class SearchFormBuilder method configFields.
// **************************************************************************
// Builder configuration
// **************************************************************************
public SearchFormBuilder configFields(String... fieldNames) {
propertyAccessors = new ArrayList<PropertyAccessor>();
for (String current : fieldNames) {
try {
PropertyAccessor accessor = classAccessor.getProperty(current);
propertyAccessors.add(accessor);
} catch (NoSuchFieldException e) {
logger.warn("Field not found: " + current, e);
}
}
return this;
}
use of com.manydesigns.elements.reflection.PropertyAccessor in project Portofino by ManyDesigns.
the class TableForm method toXhtml.
// **************************************************************************
// Implementazione di Element
// **************************************************************************
public void toXhtml(@NotNull XhtmlBuffer xb) {
xb.openElement("table");
xb.addAttribute("class", "table mde-table-form" + (condensed ? " table-condensed" : "") + (striped ? " table-striped" : ""));
if (caption != null) {
xb.writeCaption(caption);
}
xb.openElement("thead");
xb.openElement("tr");
if (selectable) {
xb.openElement("th");
xb.openElement("div");
xb.addAttribute("class", " squared-dark ");
xb.openElement("input");
xb.addAttribute("type", "checkbox");
xb.addAttribute("title", "select-all");
String id = RandomUtil.createRandomId(10);
xb.addAttribute("id", id);
String js = "$(this).closest('table').find('div." + SELECTION_CELL_CLASS + " input').prop('checked', $(this).prop('checked'));";
xb.addAttribute("onchange", js);
xb.closeElement("input");
xb.openElement("label");
xb.addAttribute("for", id);
xb.closeElement("label");
xb.closeElement("div");
xb.closeElement("th");
}
for (Column column : columns) {
xb.openElement("th");
if (column.title != null) {
xb.addAttribute("title", column.title);
}
PropertyAccessor property = column.getPropertyAccessor();
xb.addAttribute("data-property-name", property.getName());
xb.openElement("p");
xb.addAttribute("class", "form-control-static");
if (column.headerTextFormat != null) {
Map<String, Object> formatParameters = new HashMap<String, Object>();
formatParameters.put("label", StringEscapeUtils.escapeHtml(column.getActualLabel()));
formatParameters.put("property", property);
xb.writeNoHtmlEscape(column.headerTextFormat.format(formatParameters));
} else {
xb.write(column.getActualLabel());
}
xb.closeElement("p");
xb.closeElement("th");
}
xb.closeElement("tr");
xb.closeElement("thead");
if (rows.length > 0) {
xb.openElement("tbody");
for (Row row : rows) {
row.toXhtml(xb);
}
xb.closeElement("tbody");
}
xb.closeElement("table");
}
use of com.manydesigns.elements.reflection.PropertyAccessor in project Portofino by ManyDesigns.
the class TableFormBuilder method setupRows.
protected void setupRows(TableForm tableForm) {
int index = 0;
for (TableForm.Row row : tableForm.getRows()) {
String rowPrefix = StringUtils.join(new Object[] { prefix, "row", index, "_" });
for (PropertyAccessor propertyAccessor : propertyAccessors) {
Field field = buildField(propertyAccessor, rowPrefix);
if (field == null) {
logger.warn("Cannot instantiate field for property {}", propertyAccessor);
} else {
row.add(field);
}
}
// handle cascaded select fields
for (Map.Entry<String[], SelectionProvider> current : selectionProviders.entrySet()) {
setupSelectionProvidersForRow(tableForm, row, current);
}
for (Map.Entry<String[], SelectionProvider> current : rowSelectionProviders.get(index).entrySet()) {
setupSelectionProvidersForRow(tableForm, row, current);
}
index++;
}
}
use of com.manydesigns.elements.reflection.PropertyAccessor in project Portofino by ManyDesigns.
the class AbstractCrudAction method writeFormToObject.
// **************************************************************************
// Form handling
// **************************************************************************
/**
* Writes the contents of the create or edit form into the persistent object.
* Assumes that the form has already been validated.
* Also processes rich-text (HTML) fields by cleaning the submitted HTML according
* to the {@link #getWhitelist() whitelist}.
*/
protected void writeFormToObject() {
form.writeToObject(object);
for (TextField textField : FormUtil.collectEditableRichTextFields(form)) {
// TODO in bulk edit mode, the field should be skipped altogether if the checkbox is not checked.
PropertyAccessor propertyAccessor = textField.getPropertyAccessor();
String stringValue = (String) propertyAccessor.get(object);
String cleanText;
try {
Whitelist whitelist = getWhitelist();
cleanText = Jsoup.clean(stringValue, whitelist);
} catch (Throwable t) {
logger.error("Could not clean HTML, falling back to escaped text", t);
cleanText = StringEscapeUtils.escapeHtml(stringValue);
}
propertyAccessor.set(object, cleanText);
}
}
Aggregations