我有一個CouponAction類,它有兩個方法initCoupon和addCoupon。我只想驗證addCoupon方法,而不是在它嘗試驗證所有方法的類級別上進行驗證。使用Struts 2 Convetion插件驗證方法級別,而不是級別級別
這個類方法看起來是這樣的
@Scope("prototype") @Controller
@Namespace("/coupon")
public class CouponAction extends BaseAjaxAction<Coupon> {
............
@Action(value = "initPaymentCoupons", results = {
@Result(location = "/jsp/order/coupon/paymentCoupon.jsp", name = "success")
})
public String initCoupons(){
........
}
@Validations(requiredFields = {
@RequiredFieldValidator(fieldName = "couponCode", type = ValidatorType.FIELD, message = "Enter a coupon code")
})
@Action(value = "/addCoupon", [email protected]("jsonValidationWorkflowStack"),
results = {
@Result(location = "/jsp/order/coupon/paymentCoupon.jsp", name = "success")
})
public String addCoupon() {
.......
}
然後我得到:
2011-11-10 00:44:13,567 ERROR org.apache.struts2.components.ActionComponent.error:38 - Could not execute action: /coupon/initCoupons
No result defined for action vervik.actions.order.CouponAction and result input
㈣看到所有的例子使用的類級別的驗證註解。 當我使用XML我有一個文件: CouponAction-addCoupon-validation.xml 其中只驗證addCoupon方法。
我如何使它與驗證註釋一起工作?
在此先感謝。
來源:
http://struts.apache.org/2.1.6/docs/convention-plugin.html#ConventionPlugin-InterceptorRefannotation
http://struts.apache.org/2.0.14/docs/annotations.html
完美,謝謝,這是解決方案。 –
歡迎您:) –