if (!attributes.containsKey(N_TO_MANY) || metawidget.isReadOnly())
{
return;
}
HtmlCommandLink removeLink = new HtmlCommandLink();
removeLink.putAttribute("styleClass", "remove-button");
String removeExpression = COLLECTION_VAR + ".remove(" + dataTable.getAttribute("var") + ")";
removeLink.putAttribute("action", StaticFacesUtils.wrapExpression(removeExpression));
HtmlColumn column = new HtmlColumn();
column.putAttribute("headerClass", "remove-column");
column.putAttribute("footerClass", "remove-column");
column.getChildren().add(removeLink);
dataTable.getChildren().add(column);
// If bidirectional, an 'Add' button too
String inverseRelationship = attributes.get(INVERSE_RELATIONSHIP);
if (inverseRelationship != null)
{
String componentType = WidgetBuilderUtils.getComponentType(attributes);
if (componentType != null)
{
String controllerName = StringUtils.decapitalize(ClassUtils.getSimpleName(componentType));
HtmlCommandLink addLink = new HtmlCommandLink();
addLink.putAttribute("styleClass", "add-button");
String addExpression = COLLECTION_VAR + ".add(" + controllerName + "Bean.added)";
addLink.putAttribute("action", StaticFacesUtils.wrapExpression(addExpression));
// Use a f:setPropertyActionListener to initialize the bidirectional relationship
SetPropertyActionListener setPropertyActionListener = new SetPropertyActionListener();
setPropertyActionListener.putAttribute(
"target",
StaticFacesUtils.wrapExpression(controllerName + "Bean.add." + inverseRelationship));
StandardBindingProcessor bindingProcessor = metawidget.getWidgetProcessor(StandardBindingProcessor.class);
if (bindingProcessor != null)
{
bindingProcessor.processWidget(setPropertyActionListener, ENTITY, attributes,
(StaticUIMetawidget) metawidget);
}
addLink.getChildren().add(setPropertyActionListener);
// (id is useful for unit tests)
String id = StaticFacesUtils.unwrapExpression(setPropertyActionListener.getValue())
+ StringUtils.SEPARATOR_DOT_CHAR + attributes.get(NAME) + StringUtils.SEPARATOR_DOT_CHAR + "Add";
addLink.putAttribute("id", StringUtils.camelCase(id, StringUtils.SEPARATOR_DOT_CHAR));
Facet footerFacet = new Facet();
footerFacet.putAttribute("name", "footer");
footerFacet.getChildren().add(addLink);
column.getChildren().add(footerFacet);