Dashboard > RIFE > ... > Web engine > Use the format constraint to convert values during injection
RIFE Log In   View a printable version of the current page.
Use the format constraint to convert values during injection


Added by Geert Bevin, last edited by Michael Chang on Jul 23, 2008  (view change)
Labels: 
(None)

You can now specify a format constraint for a bean property. RIFE will detect it when it calls the property's setter and use it to parse the injected value. This can, for example, be used to allow users to enter a price in the local format and have it stored as a BigDecimal internally.

For example:

NumberFormat amount_format = NumberFormat.getNumberInstance(new Locale("nl", "BE"));
amount_format.setMinimumFractionDigits(2);
amount_format.setMaximumFractionDigits(2);
addGroup("donation")
  .addConstraint(new ConstrainedProperty("amount")
    .precision(10)
    .scale(2)
    .rangeBegin(new BigDecimal(0))
    .format(amount_format));

The format constraint above allows people to enter the amount 386,50 in a form's input field and have it stored automatically as the number 386.50 in the bean property.



Are you enjoying Confluence? Please consider purchasing it today.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.2.1a Build:#515 May 19, 2006) - Bug/feature request - Contact Administrators