2011-10-17 1 views
0

Account 엔티티 (JPA 상속 참조)를 확장하는 ParentAccount이라는 JPA 엔티티가 있습니다. 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"); 
      } 
     } 
    } 
} 

태피스트리 페이지 : 은 지금은하지 않는 것 태피스트리 클래스와 템플릿과 JSR-303 검증 다음은 일을해야 불행하게도

<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> 

, 비록 I @NotNull 주석이있는 항목에 주석을 추가 한 경우 해당 JSR-303 제약 조건은 무시됩니다.

아무도 도와 줄 수 있습니까?

감사합니다,

+0

Tapestry 클래스의 속성에 JSR-303 주석을 추가하면 고려해야한다는 것을 알게되었습니다. 왜 Tapestry는 JPA 엔티티의 속성에 배치 될 때 주석을 고려하지 않을까요 ?? – balteo

답변

1

나는 내가 태피스트리 클래스의 속성에 JSR-303 주석을 추가 할 경우, 그것은 고려 얻을 않는 것으로 나타났습니다. 왜 Tapestry는 JPA 엔티티의 속성에 배치 될 때 주석을 고려하지 않을까요 ??

양식에있는 모든 필드에 대해 제공된 사용자 입력 및 유효성 검사 오류를 모두 추적하는 ValidationTracker이 양식에 포함되어 있습니다.

기본값 인 ValidationTrackerImpl은 상관없는 것처럼 보입니다. 양식의 추적기 매개 변수를 통해 추적기 구현을 제공 할 수 있습니다. Struts2와 비슷한 기능을 수행하여 엔티티의 유효성을 검사했습니다.

parentAccount@Valid (JSR-303 사양 에서처럼 그래프 유효성 검사) 주석을 달았을 가능성이 있습니다 (제공되는 Tapestry에 관심 있음).

+0

감사합니다. parentAccount 속성에 @Valid 주석을 추가하려고 시도했습니다. 나는 다른 제안 된 해결책을 시도하고 이에 따라 여기에 게시 할 예정이다. – balteo