Skip to content

Attribute maxLen and minLen definition

olaf-boede edited this page Mar 14, 2014 · 9 revisions

Min/max string length of a PmAttr may be defined as follows:

Fix length via @PmAttrCfg

A definition @PmAttrCfg(minLen=2, maxLen=5) defines fix string length limits for the attribute.

Fix length via javax.validation @Size

If the PmAttr is bound to a bean field, it may re-use the @Size restriction of the bound field. Precondition for that feature:

  1. The class of the bean that contains the bound field must be known. That information is provided if
    a) the PmAttr parent is a kind of PmBean or
    b) @PmAttrCfg(beanInfoClass=MyBean.class) is specified.

  2. The bound field name must be known.
    This is automatically ensured if the field is bound to a PmAttr having the same name or via @PmAttrCfg(valuePath="pmBean.beanFieldName").
    If the field value is defined via manually implemented get/setBackingValue() methods, the corresponding bean field to read the @Size (and @NotNull) information from may be specified via @PmAttrCfg(..., beanInfoField="beanFieldName").

Dynamic length defintion

If the min/max limits depend on some dynamic conditions, you may override getMinLen() and getMaxLen() to provide your calculated limits.

Default min/max length

The default min length is zero. The default max length depends on the attribute type:

  • PmAttrString: 255
  • Subclasses of PmAttrNumBase: String length needed for decimal representation of getMaxValue().

min/max length usage

PmAttrStringImpl uses the min/max information for its validation.

For all other attribute types PmAttr.getMinLen() and PmAttr.getMaxLen() may optionally used as a hint to restrict related widgets.