Changeset 4517


Ignore:
Timestamp:
Sep 9, 2013, 11:26:15 AM (10 years ago)
Author:
Fredrik Levander
Message:

Fixes #814. Escaping the selected option list when matching.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/client/servlet/src/org/proteios/gui/form/Select.java

    r4056 r4517  
    2727 */
    2828package org.proteios.gui.form;
     29
     30import org.apache.commons.lang3.StringEscapeUtils;
    2931
    3032import se.lu.thep.waf.constraints.VParameter;
     
    5254    this.name = param.getName();
    5355    this.options = new ArrayList<Option>();
    54   setLabel(param.getName());
    55   }
    56 
    57  public Select(D param, List<Option> options)
    58   {
    59     this(param); 
    60   this.options.addAll(options);
    61   }
    62 
    63  public Select(D param, List<String> options, String selected)
     56    setLabel(param.getName());
     57  }
     58
     59
     60  public Select(D param, List<Option> options)
    6461  {
    6562    this(param);
    66   for(String str : options)
    67   {
    68     Option o = new Option(str);
    69     addOption(o);
    70   }
    71   selectOption(selected);
    72   }
    73 
    74  public Select(D param, List<Option> optionList, List<String> selected)
    75  {
    76   this(param);
    77   this.options.addAll(optionList);
    78   setMultiple(true);
    79   if (selected != null)
    80   {   
    81     for(String str : selected)
    82     {
    83       selectOption(str);
    84     }
    85   }
    86   setMaxSize(5); 
    87  }
     63    this.options.addAll(options);
     64  }
     65
     66
     67  public Select(D param, List<String> options, String selected)
     68  {
     69    this(param);
     70    for (String str : options)
     71    {
     72      Option o = new Option(str);
     73      addOption(o);
     74    }
     75    selectOption(selected);
     76  }
     77
     78
     79  public Select(D param, List<Option> optionList, List<String> selected)
     80  {
     81    this(param);
     82    this.options.addAll(optionList);
     83    setMultiple(true);
     84    if (selected != null)
     85    {
     86      for (String str : selected)
     87      {
     88        selectOption(str);
     89      }
     90    }
     91    setMaxSize(5);
     92  }
     93
    8894
    8995  public String getName()
     
    9298  }
    9399
     100
    94101  public void setName(String name)
    95102  {
     
    139146  }
    140147
     148
    141149  public Boolean isHidden()
    142150  {
     
    150158  }
    151159
    152  /**
    153   Sets number of visible options. If number of options is lower than the given size
    154   size is set to the number of options. Does nothing if there are no options.
    155  */
     160
     161  /**
     162   * Sets number of visible options. If number of options is lower than the
     163   * given size size is set to the number of options. Does nothing if there
     164   * are no options.
     165   */
    156166  public void setMaxSize(Integer size)
    157167  {
    158     if (getOptions() != null)
    159       {
    160         if (getOptions().size() < size)
    161         {
    162           setSize(getOptions().size());
    163         }
    164         else
    165         {
    166           setSize(size);
    167         }
    168       }
    169   }
    170 
    171  /**
    172   Sets all options matching the given value to selected
    173  */
    174  public void selectOption(String value)
    175  {
     168    if (getOptions() != null)
     169    {
     170      if (getOptions().size() < size)
     171      {
     172        setSize(getOptions().size());
     173      }
     174      else
     175      {
     176        setSize(size);
     177      }
     178    }
     179  }
     180
     181
     182  /**
     183   * Sets all options matching the given value to selected
     184   */
     185  public void selectOption(String value)
     186  {
    176187    // Set selected option
    177188    if (value != null)
    178189    {
     190      // The option list is escaped. So the value also need to be escaped
     191      // for proper string matching
     192      String compValue = StringEscapeUtils.escapeHtml3(value);
    179193      if (getOptions() != null)
    180194      {
    181         for( Option opt : getOptions())
     195        for (Option opt : getOptions())
    182196        {
    183           if (opt.getValue().equals(value))
     197          if (opt.getValue().equals(compValue))
    184198          {
    185199            opt.setSelected(true);
     
    190204  }
    191205
    192  
    193  /**
    194   * Sets all options matching any value in the input list to selected.
    195   *
    196   * @param selected List<Sting> selected List with selected values.
    197   */
    198  public void selectOptions(List<String> selected)
    199  {
    200    if (selected != null)
    201    {
    202      for(String str : selected)
    203      {
    204        selectOption(str);
    205      }
    206    }
    207  }
     206
     207  /**
     208  * Sets all options matching any value in the input list to selected.
     209  *
     210  * @param selected List<Sting> selected List with selected values.
     211  */
     212  public void selectOptions(List<String> selected)
     213  {
     214    if (selected != null)
     215    {
     216      for (String str : selected)
     217      {
     218        selectOption(str);
     219      }
     220    }
     221  }
    208222}
Note: See TracChangeset for help on using the changeset viewer.