Validator
에서 bean 특성을 설정하는 방법이 있습니까?
제 경우에는 validator
을 데이터베이스에 연결하고 유효성을 검사합니다.
유효성 검사가 성공적으로 완료되면 데이터베이스에서받은 객체를 bean 속성 내에 저장하려고합니다.
현재 유효성 검사기에서 bean의 정적 속성을 설정하여이 작업을 수행하고 있습니다. 그래서 내 마음에 질문
가 여기 내 검증 방법유효성 검사기의 bean 속성 설정
public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
//perform validation
if(isValidated) {
Referral ref = database.getReferral(value.toString()); //receive referral object from batabase
RegistrationBean.staticReferral = ref; // Set ref to RegistrationBean's static property
} else {
FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_FATAL, "Invalid Referral!", "Referral does not exist!");
throw new ValidatorException(msg);
}
}
이며, 여기 내 RegistrationBean
@ManagedBean
@ViewScoped
public class RegistrationBean implements Serializable {
//other bean properties
private Referral referral;
public static Referral staticReferral;
public RegistrationBean() {
//default constructor
}
public Referral getReferral() {
this.staticReferral = referral;
return referral;
}
// other getters, setters and methods
}
입니다입니다 직접 콩 속성을 설정하는 방법은
- 있는가 콩에서? ( 정적 속성 사용)
- 기존 접근 방식을 사용하여 한 사용자가 다른 사용자가 선택한 참조 객체 등을받을 수 있습니까?
덕분에 관리 콩
정적 멤버는 모든 인스턴스 (및 응용 프로그램의 사용자)간에 공유하는
@ManagedProperty
주석을 통해 관리 Bean. 멤버 변수를 정적으로 만들기 전에 최소한 두 번 생각하면됩니다. –@MattHandy 답장을 보내 주셔서 감사합니다. 정적 속성을 사용하지 않고 validator에서 bean 속성을 설정하는 방법은 무엇입니까? –
유효성 검사기를 관리 빈으로 만들면 대상 관리 빈을 유효성 검사기에 주입 할 수 있습니다. 자세한 내용은 [이 답변] (http://stackoverflow.com/a/8629655/620338)을 참조하십시오. (이 예제에서는 EJB가 삽입되었지만'@ ManagedProperty' 어노테이션을 통해 JSF 관리 빈을 삽입 할 수있다). –