我现在写了一个自己的验证类
这里面有一个set方法(红色的代码),用来给该Validator赋属性值。
public class PatronCodeValidator implements Validator
{
private KnowPatrons knowPatrons;
public void setKnowPatrons(KnowPatrons knowPatrons)
{
this.knowPatrons=knowPatrons;
}
PatronCodeValidator()
{}
public void validate(IFormComponent field,
ValidationMessages messages,
Object object) throws ValidatorException
{
String patronCode=(String)object;
if(!knowPatrons.isKnow(patronCode))
{
throw new ValidatorException("patron not found",null);
}
}
.....................................................................
}
<bean class="com.ttdev.postage.PatronCodeValidator" name="patronCodeValidator"></bean><bean class="com.ttdev.postage.PatronCodeValidator" name="patronCodeValidator"></bean>我没有使用.page文件声明该类,而在在程序中利用annotations来定义。我在页面程序的构造函数中给自定义的validator赋属性值,(程序中红色的代码)我认为完全可以取代.page文件中利用set元素赋值,但程序总是报错。盼望高手解答!
public abstract class Postage extends BasePage
{
private KnowPatrons knowPatrons;
public KnowPatrons getKonwPatrons();
@Bean
public abstract ValidationDelegate getDelegate();
@Bean
public abstract PatronCodeValidator getPatronCodeValidator();
public abstract IFieldTracking getCurrentFieldTracking();
public Postage()
{
knowPatrons=new KnowPatrons();
getPatronCodeValidator().setKnowPatrons(knowPatrons);
}
public IPage onSubmit()
{
}
}