Stripes

A mechanism to pass parameters to TypeConverters

Details

  • Type: New Feature New Feature
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Duplicate
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: Validation
  • Labels:
    None

Description

The canonical example is the ability to have a BigDecimal type converter that will automatically truncate the number down to the required scale. For example, you might want to be able to write something like:

@Validate(converterParams=@Param(name="scale" value="2") BigDecimal dollarAmount;
@Validate(converterParams=@Param(name="scale" value="0") BigDecimal liraAmount;

I don't particularly like the syntax that I've written above, but it would need to be something flexible since each converter make take a different set of parameters. Also, might need to deal with type issues - the parameter above is obviously a number but the value is expressed as a string. Perhaps it could work with:

@Param(name="foo", [numValue=N|stringValue="N"|etc.]?

Also would need to figure out how to make the type converter aware of these parameters. Do we try to inject them using setters? Or just pass across a map of key/value pairs?

Activity

Hide
Evgeny Shepelyuk added a comment - 05/Feb/09 5:24 AM

It also can be useful to make TypeConverters aware of action bean or actino bean context or any class that can provide access to request/response/servlet context.

For example i need to convert some string to integer depeding on user settings (e.g. from cookies), user input can be inches/foots/millimetres/metres etc.

And having access to servlet context from custom type converter can be very helpful in this case.

Show
Evgeny Shepelyuk added a comment - 05/Feb/09 5:24 AM It also can be useful to make TypeConverters aware of action bean or actino bean context or any class that can provide access to request/response/servlet context. For example i need to convert some string to integer depeding on user settings (e.g. from cookies), user input can be inches/foots/millimetres/metres etc. And having access to servlet context from custom type converter can be very helpful in this case.
Hide
Frederic Daoud added a comment - 19/Apr/11 3:18 PM

See STS-701

Show
Frederic Daoud added a comment - 19/Apr/11 3:18 PM See STS-701

People

  • Assignee:
    Unassigned
    Reporter:
    Andy
Vote (1)
Watch (1)

Dates

  • Created:
    30/Oct/06 5:04 AM
    Updated:
    19/Apr/11 3:18 PM
    Resolved:
    19/Apr/11 3:18 PM