Class PropertyReplacer

All Implemented Interfaces:
Serializable, Cloneable, Copyable, DictionaryBean, UifDictionaryBean

public class PropertyReplacer extends UifDictionaryBeanBase
Configuration for replacing a property value based on a condition

A Component may be configured with one or more PropertyReplacer instances. Each defines a condition to evaluate during the apply model phase, and if that condition succeeds the property on the component given by getPropertyName(), will be replaced with the value given by getReplacement(). Conditions are defined using an expression language and may reference any variables available in the component's context.

Property replacers can be used to change out an entire Component or List/Map of Components. For example, based on a condition you might want to display a TextControl or RadioControl for an InputField. You can define the field with a text control, then include a property replacer as follows:

 invalid input: '<'bean parent="PropertyReplacer" p:propertyName="control"
 p:condition="field1 eq '10985'" p:replacement-ref="RadioControl"/>

 
Note Component contains a List or property replacers which will be evaluated in the order contained within the list. So in the above example if we wanted to now add a further condition which sets the control to a checkbox, we would just add another property replacer bean. <property name="propertyReplacers"> <list> <bean parent="PropertyReplacer" p:propertyName="control" p:condition="field1 eq '10985'" p:replacement-ref="RadioControl"/> <bean parent="PropertyReplacer" p:propertyName="control" p:condition="field1 eq '11456'" p:replacement-ref="CheckboxControl"/> </list> </property> </pre>

Property replacers may be used to substitute primitive properties as well, such as Strings

Author:
Kuali Rice Team (rice.collab@kuali.org)
See Also:
  • Constructor Details

    • PropertyReplacer

      public PropertyReplacer()
  • Method Details

    • getNestedComponents

      public List<Component> getNestedComponents()
      Returns a list of nested components

      All nested components will be returned in the list. Current assumption is that PropertyReplacer can only contain a Component, List or Map for nested components

      Returns:
      nested components
    • getPropertyName

      public String getPropertyName()
      Name of the property on the Component the property replacer is associated with that will be set when the condition for the replacer succeeds

      Note the property name must be readable/writable on the component. The property name may be nested, and include Map or List references.

      Returns:
      property name to set
    • setPropertyName

      public void setPropertyName(String propertyName)
      Setter for the property name that will be set
      Parameters:
      propertyName -
    • getCondition

      public String getCondition()
      Gives the expression that should be evaluated to determine whether or not the property replacement should be made

      Expression follows SPEL and may access any model data along with any variables available in the context for the Component. The expression should evaluate to a boolean. If the resulting boolean is true, the object given by getReplacement() will be set as the value for the associated property on the component. If the resulting boolean is false, no action will take place

      Note the value does not need to contain the expression placeholder @{}

      Returns:
      expression that should be evaluated
      See Also:
    • setCondition

      public void setCondition(String condition)
      Setter for the replacement condition
      Parameters:
      condition -
    • getReplacement

      public Object getReplacement()
      Gives the Object that should be used to set the property value if the replacers condition evaluates to true

      Note the configured Object must be valid for the type given by the property on the Component. Standard property editors will be used for setting the property value

      Returns:
      instance to set
    • setReplacement

      public void setReplacement(Object replacement)
      Setter for the replacement Object
      Parameters:
      replacement -
    • completeValidation

      public void completeValidation(ValidationTrace tracer)
      Validates different requirements of component compiling a series of reports detailing information on errors found in the component. Used by the RiceDictionaryValidator.
      Parameters:
      tracer - record of component's location