McDowell と BalusC で提案されているように、Converter を作成し、それを String クラスの @FacesConvert アノテーションに登録できます。次に、getAsObject メソッドで UIComponent タイプを確認し、HtmlInputText コンポーネントのみにトリミングを適用します。
@FacesConverter(forClass = String.class)
public class StringTrimConverter implements Serializable, javax.faces.convert.Converter {
@Override
public Object getAsObject(FacesContext context, UIComponent cmp, String value) {
if (value != null && cmp instanceof HtmlInputText) {
// trim the entered value in a HtmlInputText before doing validation/updating the model
return value.trim();
}
return value;
}
@Override
public String getAsString(FacesContext context, UIComponent cmp, Object value) {
if (value != null) {
// return the value as is for presentation
return value.toString();
}
return null;
}
}