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

action tag accepts only String arrays as parameters

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.2.3.1, 2.3.1, 2.3.1.1, 2.3.20
    • 6.0.0
    • Plugin - Tags
    • None

    Description

      org.apache.struts2.components.Component accepts arbitrary objects as parameters:

          public Map getParameters() {
              return parameters;
          }
      
          ...
      
          public void addParameter(String key, Object value) {
              if (key != null) {
                  Map params = getParameters();
      
                  if (value == null) {
                      params.remove(key);
                  } else {
                      params.put(key, value);
                  }
              }
          }
      

      But org.apache.struts2.components.ActionComponent explicitly casts all his parameters to String[]:

      protected Map<String,String[]> createParametersForContext() {
              Map parentParams = null;
      
              if (!ignoreContextParams) {
                  parentParams = new ActionContext(getStack().getContext()).getParameters();
              }
      
              Map<String,String[]> newParams = (parentParams != null) 
                  ? new HashMap<String,String[]>(parentParams) 
                  : new HashMap<String,String[]>();
      
              if (parameters != null) {
                  Map<String,String[]> params = new HashMap<String,String[]>();
                  for (Iterator i = parameters.entrySet().iterator(); i.hasNext(); ) {
                      Map.Entry entry = (Map.Entry) i.next();
                      String key = (String) entry.getKey();
                      Object val = entry.getValue();
                      if (val.getClass().isArray() && String.class == val.getClass().getComponentType()) {
                          params.put(key, (String[])val);
                      } else {
                          params.put(key, new String[]{val.toString()});
                      }
                  }
                  newParams.putAll(params);
              }
              return newParams;
          }
      

      So I can't pass arbitrary objects directly to action using syntax:

      <s:action name="myAction"><s:param name="customObject" value="customObject"/></s:action>
      

      without conversion customObject->String->customObject.

      Attachments

        Issue Links

          Activity

            People

              lukaszlenart Lukasz Lenart
              paul_ik Pavel Kazlou
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 1h
                  1h