You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Ray, Marla S" <ma...@boeing.com> on 2007/02/05 21:06:43 UTC

Multiple selections with an indexed field

I have a somewhat complicated form that I'm trying to create using
Struts.  I actually have the form working but we need to make an
enhancement that makes it even more complicated.  I have tried googleing
and searching several places to find an example that will help me.  I
have found examples that solve part of the problem but not all of it.

What I have is a form that has some fixed fields and then a variable
number of other fields.  I'm using the iterate tag and the indexId to
display each of the variable fields.  It looks like:

	<logic:iterate id="field" name="infoDatas" type="InfoData"
indexId="fieldIndex">
		....
	</logic:iterate>

Within my iterate I display each field.  Some fields are displayed as
text input and some are displayed as selection lists.  The selection
list display looks like:

	<html:select property="<%=\"theValues[\"+fieldIndex+\"]\"%>">
	  <bean:define id="theSelectionList" name="field"
property="infoType.selectionList" />
	  <html:options collection="theSelectionList" property="value"
labelProperty="value" />
	</html:select>

In my Form I have theValues defined as a String array:

	private String[] theValues = {};

And I have all the proper getters and setters:

  public String[] getTheValues() {
    return theValues;
  }
  public String getTheValues(int whichone) {
    if (whichone > theValues.length-1) {
      return " ";
    }
    else {
      return theValues[whichone];
    }
  }
  public void setTheValues(String[] theValues) {
    this.theValues = theValues;
  }
  public void setTheValues (int whichone, String theValue) {
    if (theValues.length == 0) {
      this.theValues = new String[whichone+1];
    }
    else if (whichone > theValues.length-1) {
      String[] newValues = new String[whichone+1];
      for (int i=0; i<theValues.length; i++) {
        newValues[i] = theValues[i];
      }
      this.theValues = newValues;
    }
    this.theValues[whichone] = theValue;
  }

Now we need to allow the user to select multiple values for some of the
selection lists.  I'm thinking I need an array of String arrays or
something like that so I can still use the indexId but get it to allow
for multiple values but I can't find any examples of what I need and I'm
having a mental block making the jump in logic.

If someone can help me with an example or something to get me past my
mental block I would really appreciate it.

Thanks

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org