Changeset 3885


Ignore:
Timestamp:
Oct 14, 2010, 11:50:23 AM (13 years ago)
Author:
olle
Message:

Refs #700. Refs #698. Class SaveXTandemParameterSetStorage updated
to fix problems with adding string lists as list strings in hidden fields
in the form. The list string to save could be too long for the valid
VString parameter coupled to the hidden text field. A string list is now
added as a list also in the added hidden field.

  1. Class/file action/xTandemInput/SaveXTandemParameterSetStorage.java in

client/servlet updated:

  1. Private method Form addFormFields(Form targetForm, Form sourceForm)

updated to add a string list as a list also in the added hidden field.
In addition to solving the problem with strings being too long to be
saved in a hidden field coupled to a specific valid parameter, this
has the added benefit of not requiring detailed knowledge of the
data being saved.

  1. New private convenience method

void addHiddenField(Fieldset fieldset, VParameter param, String value)
added. It creates and adds a hidden field with a String value to the
given field set.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/client/servlet/src/org/proteios/action/xTandemInput/SaveXTandemParameterSetStorage.java

    r3881 r3885  
    356356  /**
    357357   * Adds form fields in source form as hidden fields to target form.
     358   *
    358359   * @param targetForm Form The form to add hidden fields to.
    359360   * @param sourceForm Form The form to take fields from.
     
    362363  private Form addFormFields(Form targetForm, Form sourceForm)
    363364  {
    364     // Get last target fieldset to add hidden fields to
     365    // Get last target field set to add hidden fields to
    365366    Fieldset targetFS = null;
    366367    for (Fieldset fieldset: targetForm.getFieldsets())
     
    371372    {
    372373      log.debug("No fieldset in form " + targetForm.getTitle() + " to add hidden fields to");
    373       // Create new fieldset without title to store hidden fields
     374      // Create new field set without title to store hidden fields
    374375      targetFS = new Fieldset();
    375376      targetForm.addFieldset(targetFS);
     
    383384      for (GUIElement guiElement: sourceFS.getFields())
    384385      {
    385          if (guiElement instanceof Select)
    386            {
    387            Select sourceS = ((Select) guiElement);
    388            TextField field = new TextField(sourceS.getParam());
    389            field.setId(sourceS.getId());
    390            field.setLabel(sourceS.getLabel());
    391            try
    392            {
    393              List<String> stringList = getValidStringList((VString) sourceS.getParam());
    394              log.debug("Source select - " + sourceS.getLabel() + " string list = " + stringList);
    395              String delimiterString = new String(",");
    396              if (sourceS.getLabel().equals("XTandemProteinTaxonEukaryotes") ||
    397                  sourceS.getLabel().equals("XTandemProteinTaxonProkaryotes"))
    398              {
    399                delimiterString = new String(", ");
    400              }
    401              String listString = stringListToListString(stringList, delimiterString);
    402              field.setValue(listString);
    403            }
    404            catch(InvalidParameterValue e)
    405            {
    406              log.debug("Source select - " + sourceS.getLabel() + " InvalidParameterValue: " + e);
    407            }
    408            log.debug("Target field - " + field.getLabel() + ": " + field.getValue());
    409            field.setHidden(true);
    410            targetFS.add(field);
    411            }
    412          else if (guiElement instanceof TextField)
    413            {
    414            TextField sourceF = ((TextField) guiElement);
    415            TextField field = new TextField(sourceF.getParam());
    416            field.setId(sourceF.getId());
    417            field.setLabel(sourceF.getLabel());
    418            field.setValue(sourceF.getValue());
    419            field.setHidden(true);
    420            targetFS.add(field);
    421            }
     386        // Get valid parameter and field label
     387        VParameter param = null;
     388        String label = null;
     389        if (guiElement instanceof Select)
     390          {
     391          Select sourceS = ((Select) guiElement);
     392          param = sourceS.getParam();
     393          label = sourceS.getLabel();
     394          }
     395        else if (guiElement instanceof TextField)
     396        {
     397          TextField sourceF = ((TextField) guiElement);
     398          param = sourceF.getParam();
     399          label = sourceF.getLabel();
     400        }
     401        // Add string list to new hidden field
     402        if (param != null)
     403        {
     404          try
     405          {
     406            List<String> stringList = getValidStringList((VString) param);
     407            log.debug("Source - " + label + " string list = " + stringList);
     408            if (stringList != null && stringList.size() > 0)
     409            {
     410              for (String value: stringList)
     411              {
     412                addHiddenField(targetFS, param, value);
     413              }
     414            }
     415          }
     416          catch(InvalidParameterValue e)
     417          {
     418            log.debug("Source - " + label + " InvalidParameterValue: " + e);
     419          }
     420        }
    422421      }
    423422    }
     
    426425
    427426
     427    /**
     428     * Creates and adds a hidden field with a String value to the given field set.
     429     *
     430     * @param fieldset Fieldset The field set to add the hidden field to.
     431     * @param param VParameter Valid parameter coupled to the hidden field.
     432     * @param value String The string value to save in the hidden field.
     433     */
     434  private void addHiddenField(Fieldset fieldset, VParameter param, String value)
     435  {
     436    TextField<String> field = new TextField<String>(param);
     437      field.setValue(value);
     438      field.setHidden(true);
     439      fieldset.add(field);
     440     }
     441
     442 
    428443  /**
    429444   * Fetches values of XTandemParameterSet variables from valid parameters
Note: See TracChangeset for help on using the changeset viewer.