Exemplo n.º 1
0
 /** {@inheritDoc} */
 @Override
 public void performInitialization(Object model) {
   List<Component> items = new ArrayList<Component>();
   List<Object> modelCollection =
       ObjectPropertyUtils.getPropertyValue(model, tabCollectionPropertyName);
   int index = 0;
   for (Object tabObj : modelCollection) {
     String idSuffix;
     if (idSuffixPropertyName != null) {
       idSuffix = ObjectPropertyUtils.getPropertyValueAsText(tabObj, idSuffixPropertyName);
     } else {
       idSuffix = Integer.toString(index);
     }
     Group newGroup = ComponentUtils.copy(groupPrototype, "_" + idSuffix);
     if (expressionProperties != null && !expressionProperties.isEmpty()) {
       Map<String, Object> tabContext = new HashMap<String, Object>();
       for (Map.Entry<String, String> entry : expressionProperties.entrySet()) {
         tabContext.put(
             entry.getKey(), ObjectPropertyUtils.getPropertyValueAsText(tabObj, entry.getValue()));
       }
       ContextUtils.pushAllToContextDeep(newGroup, tabContext);
     }
     if (setFieldBindingObjectPath && newGroup instanceof CollectionGroup) {
       ((CollectionGroup) newGroup)
           .getBindingInfo()
           .setBindingObjectPath(tabCollectionPropertyName + "[" + index + "]");
     } else if (setFieldBindingObjectPath) {
       newGroup.setFieldBindingObjectPath(tabCollectionPropertyName + "[" + index + "]");
     }
     items.add(newGroup);
     index++;
   }
   setItems(items);
   super.performInitialization(model);
 }
  /**
   * If control definition is defined on the given attribute definition, converts to an appropriate
   * control for searching (if necessary) and returns a copy for setting on the field.
   *
   * @param attributeDefinition attribute definition instance to retrieve control from
   * @return Control instance or null if not found
   */
  protected static Control convertControlToLookupControl(AttributeDefinition attributeDefinition) {
    if (attributeDefinition.getControlField() == null) {
      return null;
    }

    Control newControl = null;

    // convert checkbox to radio with yes/no/both options
    if (CheckboxControl.class.isAssignableFrom(attributeDefinition.getControlField().getClass())) {
      newControl =
          (RadioGroupControl)
              ComponentFactory.getNewComponentInstance(
                  ComponentFactory.CHECKBOX_CONVERTED_RADIO_CONTROL);
    }
    // text areas get converted to simple text inputs
    else if (TextAreaControl.class.isAssignableFrom(
        attributeDefinition.getControlField().getClass())) {
      newControl = ComponentFactory.getTextControl();
    } else {
      newControl = ComponentUtils.copy(attributeDefinition.getControlField(), "");
    }

    return newControl;
  }