For the archives, the solution I'm going with is to have the javascript add 
<html:hidden> elements to the document corresponding to the new values in the 
select.  The names of the hidden elements will be indexed.  Something like this:

Action Form:

public List<String> getOldList()

public String getSelectedValue()

public void setNewList(int index, String value)

JSP:

<html:select name="formName" property="selectedValue" styleId="myId">
     <html:options name="formName" property="oldList"/>
</html:select>

<html:submit onclick="saveSelect()"/>

<script type="text/javascript">
function saveSelect() {
     var selectControl = document.getElementById('myId);
        for (var i = 0; i < select.length; i++) {
        var hid = document.createElement("input");
        hid.type = "hidden";
        hid.name = "newList[" + i + "]";
        hid.value = selectControl.options[i].value;
        document.forms[0].appendChild(hid);
    }
}
</script>

Then the setNewList method gets called on the form with the new values from the 
select box.

If anyone has any better ideas I'm open to hearing them, but this seems to do 
the trick.

Andrew



----- Original Message ----
From: Andrew Sharpe <andrewrwsha...@yahoo.com>
To: user@struts.apache.org
Sent: Mon, March 15, 2010 6:03:30 PM
Subject: Can a collection property have its changes saved back to the 
ActionForm?

Hello all,

I have a List<String> collection that I am displaying in an
<html:select> and it is working great.  The problem is that my
jsp page makes changes to that <html:select> control via
javascript (adds new options, removes, etc).  I would like these
changes to be saved back to the ActionForm, preferrably to the same
collection where it got its data from.  

Struts does not seem to do it by default, that is, the
<html:options> tag seems to make use of the ActionForm's get
property, but not its set.  If it is supposed to behave this way please
let me know and I will reexamine my syntax.  Otherwise can someone tell
me the easiest way to do this?  I am using Struts 1.3.8 and
unfortunately cannot upgrade to Struts 2.

Many thanks in advance,

Andrew



      __________________________________________________________________
The new Internet Explorer® 8 - Faster, safer, easier.  Optimized for Yahoo!  
Get it Now for Free! at http://downloads.yahoo.com/ca/internetexplorer/

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


      __________________________________________________________________
Looking for the perfect gift? Give the gift of Flickr! 

http://www.flickr.com/gift/

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

Reply via email to