我需要你一点帮助。我在我的项目中创建了 StoreNameValidator,如果输入的商店名称已经存在于数据库中,它会检查并提示用户重新输入商店名称。它一直给我空值。我已经在调试模式下运行它。我给你发代码。请帮我。存储对象为空。请帮帮我。
///////////////////////////////////////// ///////////////////////////////////
@FacesValidator("com.kicsit.ehub.validator.StoreNameValidator")
public class StoreNameValidator implements Validator {
@ManagedProperty(value = "#{StoreService}")
private IStoreService storeService;
@Override
public void validate(FacesContext arg0, UIComponent arg1, Object storeName)
throws ValidatorException {
Store store = null;
try{
**store** = getStoreService().getStoreByName(storeName.toString());
if(store != null){
FacesMessage msg =
new FacesMessage("Store name Already Registered.",
"Already Registered.");
msg.setSeverity(FacesMessage.SEVERITY_ERROR);
throw new ValidatorException(msg);
}
}
catch(Exception ex){
}
}
public IStoreService getStoreService() {
return storeService;
}
public void setStoreService(IStoreService storeService) {
this.storeService = storeService;
}
}
在这里我正在使用这个验证器。
<p:inputText required="true" value="#{storeController.storeBean.storeName}" >
<p:ajax event="blur" update="registerMsg" />
**<f:validator validatorId="com.kicsit.ehub.validator.StoreNameValidator" />**
</p:inputText>