当向数据库插入大于4000,varchar2不够用,可以使用clob类型来存储,而在对应的EO和VO中会生成oracle.jbo.domain.ClobDomain类型;这种类型的数据在绑定到页面时,会出现类型不能转换的错误,因为页面上为返回的String类型,与ClobDomain不符合(如果只是做查询是不会有问题的)。
这时候我们可以自己定义一个转换器来解决此问题。首先编写一个java类ClobConverter,并实习Converter接口,具体代码如下:
[java]
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.ConverterException;
import oracle.jbo.domain.ClobDomain;
/**
* 页面组件String与ClobDomain类型转换
*/
public class ClobConverter implements Converter {
public Object getAsObject(FacesContext context, UIComponent
component,
String value) {
if (context == null || component == null) {
throw new NullPointerException(“FacesContext and UIComponent can
not be null”);
}
if (value == null) {
return null;
}
try {
return new ClobDomain(value);
} catch (Exception ex) {
throw new ConverterException(“Unable to convert !”, ex);
}
}
public String getAsString(FacesContext context, UIComponent
component,Object value) {
if (context == null || component == null) {
throw new NullPointerException(“FacesContext and UIComponent can
not be null”);
}
return value.toString();
}
}
[/java]
之后,在faces-config.xml中配置该转换器,配置如下:
[html]
xmlns=”http://java.sun.com/xml/ns/javaee”>
com.mainsoft.mfmi.mfc.util.ClobConverter
[/html]
最后,在页面标签中,配置该转换器就可以了。例如:
[html]
simple=”true”
required=”#{bindings.Content.hints.mandatory}”
shortDesc=”#{bindings.Content.hints.tooltip}”
id=”it2″ converter=”ClobConverter”
partialTriggers=”soc1″
binding=”#{GenerateEvaluationReport.reportContent}”
autoSubmit=”true” rows=”10″
columns=”200″ inlineStyle=”width:640px”>
[/html]