jsf - f:convertNumber doesn't throw conversion error on trailing alphabetic characters in decimal -
i using <f:convertnumber>
tag convert decimal input.
<f:convertnumber minfractiondigits="2" />
but it's accepting trailing alphabatic characters. example, if input 12345.1234aaa
converts 12345.123
. throw conversion error on instead of trimming alphabetic characters. how can achieve this?
this standard behavior of java.text.numberformat
used <f:convertnumber>
: trims entries after first not-allowed character (e.g. letters or decimal separators others ones defined in input locale). conversion fails if offending character @ beginning.
i don't behaviour because user may not notice mis-typed value got trimmed, resulting in unintended , (even worse) unnoticed auto-correction wrong value.
interestingly enough, specific number converters behave differently. using <f:converter converterid="javax.faces.double" />
not automatically handle non-numerical input, fails conversion instead. however, tag not possess additional attributes of convertnumber, such minfractiondigits or currency symbols.
a different approach write own custom converter extends standard converter described in answer. check value characters , directly abort further processing (throwing according conversion exception) if find any. if value character-free call standard behavior of converter derive from.
the drawback of both ways loose additional capabilities of convertnumber
. not have attributes such minfractiondigits
or currencysymbol
on <f:converter>
, if need you'd have find way pass in parameter. our implementation not require of these, haven't looked further (we went approach a), this answer presents approach so.
Comments
Post a Comment