Возможно, лучший способ заключается в расширении <h:inputText>
, создать свой собственный компонент, который в значительной степени так же, как <h:inputText>
но trimmes результат на по умолчанию.
На мой взгляд, хотя, должно быть атрибутом в inputText, который обрезается по умолчанию, т.е.:
<h:inputText value="#{myBean.text}" trim="true"/>
Update:
Итак, вот как вы можете создать компонент, который подрезать-х поля inputText. Обратите внимание, что я не тестировал код, поэтому я не уверен на 100%, что он будет работать, но он должен.
В faces-config.xml
Добавить ваш компонент
<component>
<component-type>foo.InputControlComponent</component-type>
<component-class>my.package.foo.InputControl</component-class>
</component>
Создать WEB-INF/foo.taglib.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE facelet-taglib PUBLIC
"-//Sun Microsystems, Inc.//DTD Facelet Taglib 1.0//EN"
"http://java.sun.com/dtd/facelet-taglib_1_0.dtd">
<facelet-taglib>
<namespace>http://whatever.com/foo</namespace>
<tag>
<tag-name>inputControl</tag-name>
<component>
<component-type>foo.InputControlComponent</component-type>
</component>
</tag>
</facelet-taglib>
В web.xml
<context-param>
<param-name>facelets.LIBRARIES</param-name>
<param-value>/WEB-INF/foo.taglib.xml</param-value>
</context-param>
InputControl.java
public class InputControl extends UIPanel {
public InputControl() {
super();
}
private void childrenEncodeBegin(FacesContext context, List<UIComponent> children) {
for (UIComponent comp : children) {
if (comp instanceof UIInput) {
comp = (UIInput) comp;
((UIInput) comp).setValue(((UIInput) comp).getValue().toString().trim());
}
// Encode recursively
if (comp.isRendered() && comp.getChildCount() > 0)
childrenEncodeBegin(context, comp.getChildren());
}
}
public void encodeBegin(FacesContext context) throws IOException {
if (getChildren() != null)
childrenEncodeBegin(context, getChildren());
}
}
Теперь в вашем XHTML вы можете использовать его как это:
<foo:inputControl>
<ui:include src="myForm.xhtml"/>
</foo:inputControl>
http://stackoverflow.com/a/8327848/617373 – Daniel