Uploaded image for project: 'Struts 2'
  1. Struts 2
  2. WW-4702

List based parameters no longer work when there is only one value.

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.5.5
    • 2.5.8
    • None
    • None

    Description

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

      Consider the basic action below.

      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;
      	}
      }
      

      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 break this behavior. because XWorkListPropertyAccessor Expects an Array of strings for value (which was previously sent when HttpParameters was a map instead of an Object).

      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());
      }
      

      Attachments

        Issue Links

          Activity

            People

              lukaszlenart Lukasz Lenart
              agreenfield Adam Greenfield
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: