Changeset 5585


Ignore:
Timestamp:
Mar 15, 2011, 2:41:24 PM (13 years ago)
Author:
Nicklas Nordborg
Message:

Fixes #1585: Problem with 'null' parameter values in plug-in configuration when handling errors

Location:
branches/2.17-stable
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/2.17-stable/src/core/net/sf/basedb/core/ParameterValuesImpl.java

    r4941 r5585  
    175175    type.validate(name, value);
    176176    List<T> l = new ArrayList<T>(1);
    177     l.add(value);
     177    if (value != null) l.add(value);
    178178    parameters.put(name, l);
    179179    parameterTypes.put(name, type);
     
    195195    }
    196196    type.validate(name, values);
    197     parameters.put(name, values);
     197    // Create copy of list but remove null values
     198    ArrayList<T> l = new ArrayList<T>(values.size());
     199    for (T value : values)
     200    {
     201      if (value != null) l.add(value);
     202    }
     203    parameters.put(name, l);
    198204    parameterTypes.put(name, type);
    199205  }
  • branches/2.17-stable/www/common/plugin/configure.jsp

    r5558 r5585  
    197197              values = Collections.singletonList(pType.getItems().get(0)); 
    198198            }
     199            %>
     200            var values = new Array();
     201            <%
     202            int numNotNullValues = 0;
     203            if (values != null && values.size() > 0)
     204            {
     205              for (Object value : values)
     206              {
     207                if (value instanceof Date)
     208                {
     209                  if (pType.isEnumeration())
     210                  {
     211                    value = ((Date)value).getTime();
     212                  }
     213                  else
     214                  {
     215                    if (pType.getValueType() == Type.TIMESTAMP)
     216                    {
     217                      value = dateTimeFormatter.format((Date)value);
     218                    }
     219                    else
     220                    {
     221                      value = dateFormatter.format((Date)value);
     222                    }
     223                  }
     224                }
     225                else if (value instanceof File && pType instanceof FileParameterType)
     226                {
     227                  File file = File.getById(dc, ((File)value).getId());
     228                  value = file.getPath().toString();
     229                }
     230                else if (value instanceof BasicItem)
     231                {
     232                  value = ((BasicItem)value).getId();
     233                }
     234                if (value != null)
     235                {
     236                  numNotNullValues++;
     237                  %>
     238                  values[values.length] = '<%=HTML.javaScriptEncode(value.toString())%>';
     239                  <%
     240                }
     241              }
     242            }
     243            %>
     244            new Parameter('<%=name%>', '<%=HTML.javaScriptEncode(param.getLabel())%>', <%=pType.getMultiplicity()%>, <%=pType.isEnumeration()%>, <%=pType.getNotNull()%>, values);
     245            <%
    199246            String icon = "";
    200             if (values != null && values.size() > 0)
     247            if (numNotNullValues > 0)
    201248            {
    202249              icon = pType.getNotNull() ? "required_values.gif" : "notrequired_values.gif";
     
    213260              sb.append(icon+"<span class=\"label\">"+label+"</span></div>\n");
    214261            }
    215             %>
    216             var values = new Array();
    217             <%
    218             if (values != null && values.size() > 0)
    219             {
    220               for (Object value : values)
    221               {
    222                 if (value instanceof Date)
    223                 {
    224                   if (pType.isEnumeration())
    225                   {
    226                     value = ((Date)value).getTime();
    227                   }
    228                   else
    229                   {
    230                     if (pType.getValueType() == Type.TIMESTAMP)
    231                     {
    232                       value = dateTimeFormatter.format((Date)value);
    233                     }
    234                     else
    235                     {
    236                       value = dateFormatter.format((Date)value);
    237                     }
    238                   }
    239                 }
    240                 else if (value instanceof File && pType instanceof FileParameterType)
    241                 {
    242                   File file = File.getById(dc, ((File)value).getId());
    243                   value = file.getPath().toString();
    244                 }
    245                 else if (value instanceof BasicItem)
    246                 {
    247                   value = ((BasicItem)value).getId();
    248                 }
    249                 %>
    250                 values[values.length] = '<%=HTML.javaScriptEncode(value == null ? "" : value.toString())%>';
    251                 <%
    252               }
    253             }
    254             %>
    255             new Parameter('<%=name%>', '<%=HTML.javaScriptEncode(param.getLabel())%>', <%=pType.getMultiplicity()%>, <%=pType.isEnumeration()%>, <%=pType.getNotNull()%>, values);
    256             <%
    257262          }
    258263          else
Note: See TracChangeset for help on using the changeset viewer.