Managed bean property value not set to null

Posted by Vladimir on Stack Overflow See other posts from Stack Overflow or by Vladimir
Published on 2010-05-17T14:44:06Z Indexed on 2010/05/17 16:00 UTC
Read the original article Hit count: 276

Filed under:
|
|
|

Hi!

I'm new to JSF, so this question might be strange. I have an inputText component's value bound to managed bean's property of type Float. I need to set property to null when inputText field is empty, not to 0 value. It's not done by default, so I added converter with the following method implemented:

public Object getAsObject(FacesContext arg0, UIComponent arg1, String arg2) throws ConverterException {
 if (StringUtils.isEmpty(arg2)) {
  return null;
 }

 float result = Float.parseFloat(arg2);
 if (result == 0) {
  return null;
 }
 return result;
}

I registered converter, and assigned it to inputText component. I logged arg2 argument, and also logged return value from getAsObject method. By my log I can see that it returns null value. But, I also log setter property on backing bean and argument is 0 value, not null as expected. To be more precise, it is setter property is called twice, once with null argument, second time with 0 value argument.

It still sets backing bean value to 0. How can I set value to null?

Thanks in advance.

© Stack Overflow or respective owner

Related posts about java

Related posts about jsf