struts-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Adam Greenfield (JIRA)" <j...@apache.org>
Subject [jira] [Created] (WW-4702) List based parameters no longer work when there is only one value.
Date Tue, 25 Oct 2016 20:01:00 GMT
Adam Greenfield created WW-4702:
-----------------------------------

             Summary: List based parameters no longer work when there is only one value.
                 Key: WW-4702
                 URL: https://issues.apache.org/jira/browse/WW-4702
             Project: Struts 2
          Issue Type: Bug
    Affects Versions: 2.5.5
            Reporter: Adam Greenfield


If an action has a List parameter, but is only called with one value, the parameter is never
set.

Consider the basic action below.

{noformat}
public class TestAction
{
	private List<SomeObject> object;

	public String execute()
	{
		for (SomeObject user : object)
		{
			System.out.println("as list" + user.field);
		}
		return "success";
	}

	public static class SomeObject{
		private String field;

		public void setField(String field)
		{
			this.field = field;
		}
	}

	public List<SomeObject> getObject()
	{
		return object;
	}

	public void setObject(List<SomeObject> object)
	{
		this.object = object;
	}
}
{noformat}

Performing a GET on "/test.action?object.field=a" 
Expected outcome: "object" list should be populated with 1 object. with a field value of "a"
Actual Outcome: object list is empty.

Performing a GET on "/test.action?object.field=a&object.field=b" works as expected (list
has 2 entries). 

The following changes to [ParametersInterceptor|https://fisheye6.atlassian.com/browse/struts/core/src/main/java/com/opensymphony/xwork2/interceptor/ParametersInterceptor.java?r=6ab6ec879cc9eb1997b88856173d2123b32509ee#to206]
break this behavior. because [XWorkListPropertyAccessor|https://fisheye6.atlassian.com/browse/struts/core/src/main/java/com/opensymphony/xwork2/ognl/accessor/XWorkListPropertyAccessor.java?r=c7fdf7ffc5aa6744e9f3dc16c490aa0abc65f993#to138]
Expects an Array of strings for value (which was previously sent when HttpParameters was a
map instead of an Object).

{noformat}
if (value instanceof Parameter.File) {
     newStack.setParameter(name, value.getObject());
} else  if (value.isMultiple()) {
    newStack.setParameter(name, value.getMultipleValues());
} else {
     newStack.setParameter(name, value.getValue());
}
{noformat}





--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message