Details
-
Bug
-
Status: Open
-
Major
-
Resolution: Unresolved
-
2.1.6
-
None
-
None
Description
I'm upgraded an app under development to the latest Struts release (2.1.8) which includes XWork 2.1.6 for validation. It appears that if I have an action with two beans on it, and specify in the actions xml validation file that it should perform visitor validation for each of the beans under a different context, the second beans validation uses the first beans context rather than the one I specify. A minimal test case to illustrate this is:
(VisitorBugAction.java)
import com.opensymphony.xwork2.ActionSupport;
public class VisitorBugAction extends ActionSupport {
private final BugBean firstBean = new BugBean();
private final BugBean secondBean = new BugBean();
public BugBean getFirstBean()
{ return firstBean; }public BugBean getSecondBean()
{ return secondBean; }}
(VisitorBugAction-validation.xml)
<!DOCTYPE validators PUBLIC "-//OpenSymphony Group//XWork Validator 1.0.2//EN" "http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">
<validators>
<field name="firstBean">
<field-validator type="visitor">
<param name="appendPrefix">true</param>
<param name="context">mandatoryA</param>
<message>firstBean: </message>
</field-validator>
</field>
<field name="secondBean">
<field-validator type="visitor">
<param name="appendPrefix">true</param>
<param name="context">mandatoryB</param>
<message>secondBean: </message>
</field-validator>
</field>
</validators>
(BugBean.java)
public class BugBean {
private String fieldA;
private String fieldB;
public String getFieldA()
{ return fieldA; }public void setFieldA(String fieldA)
{ this.fieldA = fieldA; }public String getFieldB()
{ return fieldB; }public void setFieldB(String fieldB)
{ this.fieldB = fieldB; }}
(BugBean-mandatoryA-validation.xml)
<!DOCTYPE validators PUBLIC "-//OpenSymphony Group//XWork Validator 1.0.2//EN" "http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">
<validators>
<field name="fieldA">
<field-validator type="requiredstring">
<message>fieldA required</message>
</field-validator>
</field>
</validators>
(BugBean-mandatoryB-validation.xml)
<!DOCTYPE validators PUBLIC "-//OpenSymphony Group//XWork Validator 1.0.2//EN" "http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">
<validators>
<field name="fieldB">
<field-validator type="requiredstring">
<message>fieldB required</message>
</field-validator>
</field>
</validators>
(struts.xml fragment)
<package name="test" extends="struts-default">
<action name="visitorBug!*" class="VisitorBugAction" method="
{1}">
<result name="input">/WEB-INF/jsp/visitorBug.jsp</result>
<result name="success">/WEB-INF/jsp/visitorBug.jsp</result>
</action>
</package>
(visitorBug.jsp)
<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<s:form>
<h1>First bean (A is mandatory)</h1>
<s:textfield name="firstBean.fieldA" label="Field A" />
<s:textfield name="firstBean.fieldB" label="Field B" />
<h1>Second bean (B is mandatory)</h1>
<s:textfield name="secondBean.fieldA" label="Field A" />
<s:textfield name="secondBean.fieldB" label="Field B" />
<s:submit label="Submit" action="visitorBug!execute" />
</s:form>
Expected behavior: on submit from an empty page, field A on first bean and field B on second bean will have validation errors
Actual behavior: field A on both beans has a validation error
This is definitely a regression, as the unexpected behaviour only started exhibiting itself when I upgraded from Struts 2.1.6.