That's normal and natural behaviour and not JSF specific. A blank space may be perfectly valid input. The required="true"
only kicks in on empty inputs, not in filled inputs. In JSF you can however just create a Converter
for String
class to automatically trim the whitespace.
@FacesConverter(forClass=String.class)
public class StringTrimmer implements Converter {
@Override
public Object getAsObject(FacesContext context, UIComponent component, String value) {
return value != null ? value.trim() : null;
}
@Override
public String getAsString(FacesContext context, UIComponent component, Object value) {
return (String) value;
}
}
Put this class somewhere in your project. It'll be registered automatically thanks to @FacesConverter
and invoked automatically for every String
entry thanks to forClass=String.class
.
No need to hack the JSF API/impl. This makes no sense.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…