结果发现错误(字段和操作不会跨链维护。
以下证明了这一点(假设 struts2-conventions-plugin-VERSION):
动作 foo 总是链接到动作栏(所以我们只需要动作栏的视图)
行动富
package com.quaternion.action;
import com.opensymphony.xwork2.ActionSupport;
import org.apache.struts2.convention.annotation.Result;
/** #1 SOMETHING WILL BE ADDED HERE TO FIX THE ISSUE**/
@Result(name="input", type="chain", location="bar")
public class Foo extends ActionSupport{
private String name;
@Override
public void validate(){
super.addActionError("Just an action error");
super.addFieldError("name", "Name is all ways wrong... for no good reason.");
}
public String getName(){
return name;
}
public void setName(String name){
this.name = name;
}
}
操作栏
package com.quaternion.action;
import com.opensymphony.xwork2.ActionSupport;
/** #2 SOMETHING WILL BE ADDED HERE TO FIX THE ISSUE**/
public class Bar extends ActionSupport{
}
查看栏:/WEB-INF/content/bar.jsp
<%@taglib prefix="s" uri="/struts-tags"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<body>
<h1>Action Bar</h1>
<s:actionerror/>
<s:fielderror name="name"/>
</body>
</html>
测试上述内容,我们发现错误中没有显示任何内容。
为了解决这个问题,我们使用了商店拦截器:http ://struts.apache.org/2.0.14/struts2-core/apidocs/org/apache/struts2/interceptor/MessageStoreInterceptor.html
In the first action (#1) we will need to add annotations and the imports to support them:
import org.apache.struts2.convention.annotation.InterceptorRef;
import org.apache.struts2.convention.annotation.InterceptorRefs;
@InterceptorRefs({
@InterceptorRef(value = "store", params = {"operationMode","STORE"}),
@InterceptorRef("defaultStack"),
})
In the second action (#2) we will need to add annotations and the imports to support them:
import org.apache.struts2.convention.annotation.InterceptorRef;
import org.apache.struts2.convention.annotation.InterceptorRefs;
@InterceptorRefs({
@InterceptorRef(value = "store", params = {"operationMode","RETRIEVE"}),
@InterceptorRef("defaultStack"),
})
And now it works.