2011-12-22 2 views
3

PlayFramework 및 데이터 바인딩의 유효성 검사를 사용하여 일부 필드를 바인딩하지 않도록 데코레이터를 통해 가능할 수 있습니까? 예를 들어일부 필드의 바인딩을 방지하려면 어떻게해야합니까?

,이 모델이 있습니다

class User extends Model { 
    @Required 
    @Email 
    public String email; 

    // I'd like to avoid setting this 
    public String password; 
} 

을 내 모델 :

Store store = new Store(); 
Binder.bindBean(params.getRootParamNode(), store, null);   
validation.valid(store); 

사용자 POST 이메일 및 비밀번호는 비밀번호가 설정 될 경우,하지만 난하지 않습니다 고 싶어요.

어떻게하면됩니까?

답변

4

당신은 데이터를 유지하고 싶지 않아,하지만 당신은 그것이 ... 자동 바인딩, 당신이 사용할 수있는 @Transient 주석의 일환으로

class User extends Model { 
    @Required 
    @Email 
    public String email; 

    // I'd like to avoid setting this 
    @Transient 
    public String password; 
} 
을 구속하려면

당신이 전혀 구속하지 않으려면, 다음 NoBinding annotation

@play.data.binding.NoBinding 

를 사용
public class User extends Model { 
    @NoBinding("profile") public boolean isAdmin; 
    @As("dd, MM yyyy") Date birthDate; 
    public String name; 
} 
관련 문제