Meaningless Drivel is fun!
The moose likes Struts and the fly likes Mapping list to type Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Mapping list to type" Watch "Mapping list to type" New topic

Mapping list to type

Dompuk Kogepan

Joined: Apr 03, 2006
Posts: 1
Hi all!

I have made a jsp-page, contaning two muliplte selection lists.
One of them is pre-populated with entries from the beginning, the other is empty. With a java-script i can move the entries from one list to the other.

Now, to my problem:
When i hit submit, i would like to save all the entries in the list that was empty from the beginning.

I have mapped the form against a POJO in the following way:
<form-bean name="listaForm" type="org.apache.struts.validator.DynaValidatorForm">
<form-property name="lista" type="mypackage.Lista" />

Can I map the list directly against an list-type? Eg. ArrayList in the POJO? Or how can i do it in another way?

Please help, i will be eternally greatful for any answer

Sometimes, but not always
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
No, struts won't map selected options in an <html:select> control directly to a List. You must use a String array for this. (type = java.lang.String[]) If you want to transfer the String array to a list, you'll have to write code to do that yourself once Struts has populated the String array.

Consultant, Sima Solutions
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
I have written java script that will select all the items in the "selected" list box and then submit the form. This way the values get submitted with the form. I could try to track down an example if you have trouble getting the JSP to work.

- Brent
I agree. Here's the link:
subject: Mapping list to type
It's not a secret anymore!