views:

42

answers:

1

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 use object.toString()
  • in the getAsObject(..) method use new BigDecimal(str) / Double.parseDouble(str) / Integer.parseInt(str). Use instanceof to differentiate between the types.
  • register the converter in faces-config.xml.
Bozho
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
@Csaryus - I can write it instead of you, but make some effort. My explanation should be sufficient to implement the class you need.
Bozho
@bozho. It's true, but I was having a time constraint.
Csaryus