代码如下:
public class TextFilteredPropertyColumnIntConvert extends TextFilteredPropertyColumn{
public TextFilteredPropertyColumnIntConvert(IModel displayModel, String propertyExpression) {
super(displayModel, propertyExpression);
}
public Component getFilter(String componentId, FilterForm form) {
return new TextFilterIntConvert(componentId,getFilterModel(form),form);
}
}
public class TextFilterIntConvert extends AbstractFilter{
private static final long serialVersionUID = 1L;
private final TextField filter;
public TextFilterIntConvert(String id, IModel model, FilterForm form){
super(id, form);
filter = new TextField("filter", model){
public IConverter getConverter() {
return new SimpleConverterAdapter(){
public String toString(Object value){
return value != null ? value.toString() : null;
}
public Object toObject(String value) {
Long l = new Long(0);
try{
l = Long.valueOf(value);
}catch(Exception e){
e.printStackTrace();
}
return l;
}
};
}
};
filter.setConvertEmptyInputStringToNull(false);//TextField默认设为true,如果没有输入,转为null。此处设为空字符串""
enableFocusTracking(filter);
add(filter);
}
public final TextField getFilter(){
return filter;
}
}