The link you posted says that the converter should work with a zero value, but donβt say that the converter will be called in every situation with zero values.
Specifically, it does not say that the converter will be called when it is inside h:outputText , and the value is null.
If you dig into Mojarra sources, you will see:
//Line 355 -- com.sun.faces.renderkit.html_basic.HtmlBasicRenderer //method getCurrentValue Object currentObj = getValue(component); if (currentObj != null) { currentValue = getFormattedValue(context, component, currentObj); }
Clearly, a null value will never be converted! And I could not find a workaround.
Then, if you really need your value to be zero (you could return 0 or something else), I think your only chance is to do your own rendering. It is very simple:
You are writing a renderer that overrides a method that matters:
package my; import javax.faces.component.UIComponent; import javax.faces.component.UIInput; import javax.faces.context.FacesContext; import com.sun.faces.renderkit.html_basic.TextRenderer; public class HtmlCustomRenderer extends TextRenderer { @Override public String getCurrentValue(FacesContext context, UIComponent component) { if (component instanceof UIInput) { Object submittedValue = ((UIInput) component).getSubmittedValue(); if (submittedValue != null) {
And then declare the renderer in faces-config.xml:
<render-kit> <renderer> <component-family>javax.faces.Output</component-family> <renderer-type>javax.faces.Text</renderer-type> <renderer-class>my.HtmlCustomRenderer</renderer-class> </renderer> </render-kit>
Now your converter will be called with zero values!
Hope this helps!
source share