aspose file tools*
The moose likes Struts and the fly likes DynaActionForm properties not correctly set with checkboxes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "DynaActionForm properties not correctly set with checkboxes" Watch "DynaActionForm properties not correctly set with checkboxes" New topic
Author

DynaActionForm properties not correctly set with checkboxes

Roscoe Padsmith
Greenhorn

Joined: Apr 10, 2008
Posts: 7
Hi all,

What I'm trying to do is fill the property "choice" (String[]) of different "CopyVacationForm"s. What I have is a CopyVacationsForm which is a DynaActionForm containing a CopyVacationForm[] property cvfs.

My form bean has the correct getters and I'm not getting any errors but when I submit it it's not filled with the values I wanted.


In my jsp I do :




In my Struts-config.xml I have :



Other values of the form beans are correctly set but dealing with checkboxes and String arrays seems to be a problem.

Any help or suggestion would be really appreciated.
Thanks in advance.

-- Alain
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Add indexed="true" to your html-el:checkbox tag and change the name attribute from cvf to cvfs.
[ June 11, 2008: Message edited by: Merrill Higginson ]

Merrill
Consultant, Sima Solutions
Roscoe Padsmith
Greenhorn

Joined: Apr 10, 2008
Posts: 7
Thank you for answering so quickly.

I already tried using indexed properties but I got an out of bounds exception because some of the records (from sitePlanRecords.records) are actually not displayed (yes I tried to clear some of the dark side of my code for better readability ).

I managed to get contents of "choice" using String [] choice = request.getParameterValues("choice") in my Action class but what I get is a big array with all the values (that were checked) in it so i changed the value property of the checkbox with value="${cvf.idEmployee},${record.numDay}". This way I get the matching line (i.e. employee) with some string tokenizing. I know it's a bit dirty but it's the best (actually only) way i could think of.

Don't hesitate if you have better ideas.

Regards,

-- Alain
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
This link explains why you were getting index out of bound errors.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: DynaActionForm properties not correctly set with checkboxes