我有一個名爲ParentAccount
的JPA實體,它擴展了抽象Account
實體(請參閱JPA繼承)。我已將JSR-303驗證約束放置在Account實體中。 現在我有以下的掛毯類和模板和JSR-303的驗證似乎不工作:關於JSR-303,Tapestry和JPA實體繼承的複雜用例
掛毯類:
public class Inscription {
@Property
//this is not validated...
private ParentAccount parentAccount;
@Property
@Validate("required")
private String accountPasswordConfirmation;
@InjectComponent
private Form registrationForm;
@OnEvent(EventConstants.PREPARE)
void prepareAccount(){
parentAccount = new ParentAccount();
}
@OnEvent(value= EventConstants.VALIDATE)
void validateRegistrationForm() {
if(registrationForm.isValid()) {
if(accountPasswordConfirmation.equals(parentAccount.getAccountPassword())) {
System.out.println("ok for insert");
}
}
}
}
Tapestry頁面:
<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd">
<head>
<title>Hello World Page</title>
</head>
<body>
<form t:type="form" t:id="registrationForm" validate="this">
<t:errors/>
<div>
<label t:type="label" for="accountEmailAddress"/>
<input t:type="textfield" t:id="accountEmailAddress" value="parentAccount.accountEmailAddress"/>
</div>
<div>
<label t:type="label" for="accountFirstName"/>
<input t:type="textfield" t:id="accountFirstName" value="parentAccount.accountFirstName"/>
</div>
<div>
<label t:type="label" for="accountLastName"/>
<input t:type="textfield" t:id="accountLastName" value="parentAccount.accountLastName"/>
</div>
<div>
<label t:type="label" for="accountPassword"/>
<input t:type="textfield" t:id="accountPassword" value="parentAccount.accountPassword"/>
</div>
<div>
<label t:type="label" for="accountPasswordConfirmation"/>
<input t:type="textfield" t:id="accountPasswordConfirmation" value="accountPasswordConfirmation"/>
</div>
<div><input type="submit" value="ok"/></div>
</form>
</body>
</html>
不幸的是,儘管我已經使用@NotNull
註釋註釋了實體,那些JSR-303約束被忽略。
任何人都可以請幫忙嗎?
問候,
我注意到,如果我將一個JSR-303註釋添加到Tapestry類中的屬性,它會考慮到。那麼爲什麼Tapestry在放入JPA實體的屬性時不會考慮註釋? – balteo 2011-10-17 15:44:54