【发布时间】:2014-05-31 00:28:23
【问题描述】:
我有这个视图的网络流:
<var name="newRecipe" class="springapp.service.NewRecipe" />
<view-state id="displayNameView" view="/WEB-INF/jsp/add_name.jsp" model="newRecipe">
<transition on="nameEntered" to="displayDescriptionView" />
</view-state>
和验证者:
@Component("newRecipeValidator")
public class NewRecipeValidator implements Validator {
@Override
public boolean supports(@SuppressWarnings("rawtypes") final Class clazz) {
return NewRecipe.class.isAssignableFrom(clazz);
}
@Override
public void validate(final Object obj, final Errors errors) {
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "error.not-specified-name", "Pole wymagane.");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "description", "error.not-specified-description", "Pole wymagane.");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "category", "error.not-specified-category", "Pole wymagane.");
}
public void validateDisplayNameView(final NewRecipe obj, final ValidationContext context) {
System.out.println("okej");
}
}
我的问题是,当 Web 流尝试验证视图 displayNameView 时,它会调用 validateDisplayNameView(),然后再调用 validate()。
在 validate() 中(用于视图 displayNameView)newRecipe 总是会有空字段描述和类别。
【问题讨论】:
标签: java spring validation spring-webflow spring-webflow-2