Data conversion

Print

 

When a method is called, its input parameters are populated with values received from request, which are converted to the type of the method parameter to which it is bound. 

Accepted method parameter types are byte, Byte, char, Character, short, Short, int, Integer, float, Float , long, Long, double, Double, boolean, Boolean, Date, String, net.sourceforge.javajax.UploadFile and their respective arrays. 
Any other type would be treated as a bean. 

Date parameters are converted considering the received value a Long representing the value of the Date in milliseconds. Additional formats can be specified in an init-param of the servlet in web.xml file:

<init-param>
<param-name>date.formats</param-name>
<param-value>dd MMM yyyy | yyyy-MM-dd | dd-MM-yyyy | ddd, dd MMM yyyy</param-value>
</init-param>


That is, a pipe ( | ) separated list of valid date format. All of them will be used when trying to generate a date from a receiverd parameter, if a valid Date object can not be created an "invalid.format" message is generated for the specified field. 

Number parameters can be passed with or without integer/decimal separator. Correct format is evaluated based on a Locale object, that describes which are, for that locale, the correct separators we should expect in the number. 
By default, user locale is used to perform conversion, or you can specify in web.xml an application level Locale that must be used: 

<init-param>
<param-name>conversion.locale</param-name>
<param-value>EN-us</param-value>
</init-param>