It's a little old question, but I resolved this issue by implementing another solution (I think in an easier way).
I implement a TypeConverter
to convert empty string to null.
Two files is necessary :
The converter.
public class StringEmptyToNullConverter implements TypeConverter {
private static final Logger log = LoggerFactory.getLogger(StringEmptyToNullConverter.class);
@Override
public Object convertValue(Map arg0, Object arg1, Member member, String arg3, Object obj, Class arg5) {
String[] value = (String[]) obj;
if (value == null || value[0] == null || value[0].isEmpty()) {
logDebug("is null or empty: return null");
return null;
}
logDebug("not null and not empty: return '{}'", value[0]);
return value[0];
}
private void logDebug(String msg, Object... obj) {
if (log.isDebugEnabled()) {
log.debug(msg, obj);
}
}
}
And the register, named xwork-conversion.properties
. You have to put this file in your java path.
# syntax: <type> = <converterClassName>
java.lang.String = StringEmptyToNullConverter
see the struts converter documentation
null
? – Emigration