我在自定义验证中使用这种方式如果我假设我有这种形式,如果这种方式正确与否,我会有点困惑:
<h:form id="myForm>
<h:outputText value="user name" />
<h:inputText value="#userBean.userName" id="userName" />
<h:outputText value="Password" />
<h:inputText value="#userBean.Password" id="passwd" />
</h:form>
我有它的托管豆:
@ManagedBean(name="userBean")
@SessionScoped
public class UserBeanData{
private String userName;
private String password;
// with setters and getters........
//
}
以及用于验证托管 Bean 字段和实施的自定义验证器,例如:
@Override
public validate(FacesContext context, UIComponent component, Object value) throws ValidatorException{
Map<String, String> params = context.getExternalContext().getRequestParametersMap();
String username = params.get("myForm:username");
String pass = params.get("myForm:passwd");
// validate : if fields are not null check if the user exists if the result is empty , throws a validation Message Error
}
我的问题是:像这样检索托管 bean 值是真的还是假的????