SelectBooleanCheckbox Converter

Problem

Many programer run into problems when they want to use Converter with SelectBooleanCheckbox, which does not work accordingly. The RenderResponse phase converts an custom object correct, but on postback the ProcessValidation phase runs into Conversion Error.

Checking the source code detects, that the class CheckboxRenderer does not call the converter at all, instead it returns always an Boolean object. The opened bug Issue 456 has been moved from implementation to specification and will not be solved soon.

Solution

If you nevertheless want to use SelectBooleanCheckbox with different object types like String you can code an own CheckboxRenderer. This is very easy, just extend the standard renderer class [4] and overwrite the following method:

public Object getConvertedValue(FacesContext context, UIComponent component, Object submittedValue) throws ConverterException { Converter converter = ((ValueHolder) component).getConverter(); return converter.getAsObject(context, component, (String)submittedValue); }

You should just now, how to register own renderer, because this is not easy in JSF!

Resources

[1] JSF 1.2 (Mojarra)
[2] h:selectBooleanCheckbox
[3] javax.faces.component.html.HtmlSelectBooleanCheckbox
[4] com.sun.faces.renderkit.html_basic.CheckboxRenderer

Johannes Hammoud SelectBooleanCheckbox Converter 24.10.2007

I Coding : Community about Java programing

Language German+-

Java JSF JavaScript HTML CSS NetBeans GlassFish MySQL

Imprint

Visits
5744585
Today
154