I want to convert the text entered by someone into a textbox into a double(for example), and automatically set up the value of an bean field with that double.
+1
A:
- implement
javax.faces.convert.Converter - in the
getAsString(..)method useobject.toString() - in the
getAsObject(..)method usenew BigDecimal(str)/Double.parseDouble(str)/Integer.parseInt(str). Useinstanceofto differentiate between the types. - register the converter in faces-config.xml.
Bozho
2010-10-19 20:33:38
the answer is a little bit to vague for my level of java. I'd be thankful if you coud be a little bit more explicit. Practically I have a bean with 2 strings which should be numbers(BigDecimal, double, int). How can I do this with a converter?
Csaryus
2010-10-20 00:17:59
@Csaryus - I can write it instead of you, but make some effort. My explanation should be sufficient to implement the class you need.
Bozho
2010-10-20 05:50:26
@bozho. It's true, but I was having a time constraint.
Csaryus
2010-10-20 12:22:10