• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

dynamic checkboxes in struts 2

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!

I'm having trouble with the following scenario.
I generate a table with a column in which i place a checkbox per row. The number of checkboxes created depends on the size of a collection. Something similar to the gmail inbox folder. I want to be able to select one or more of these checkboxes to perform some action over the objects they represent (remove them in my case)

If i use checkboxlist tag in my jsp page, (lets say i have 10 objects in the collection) it displays the 10 checkboxes toguether, and not one in each row (dont know how to format that)

So i decided to try the checkbox tag, but i cant get the values in my action class.

I have something like this:

<s:iterator value="taxSystem.operations" status="rowstatus">
<tr>
<td>
<s roperty value="#rowstatus.index" />
</td>

<td align="center">
<s roperty value="operationName" />
</td>

<td align="center">
<s roperty value="code"/>
</td>

<td align="center">
<s:checkbox name="selectedOperations[#rowstatus.index]" theme="simple" />
</td>
</tr>
</s:iterator>

In my class action i have a variable String[]selectedOperations with setter and getter... but when i see what gets inside i have only the position [0] with a String like this: "true, true, true" depending on how many checkboxes were checked. The thing is that i cant distinguis which true corresponds with which checkbox since empty checkboxes dont include "false" to that String.

Can anybody give a hand and tell me what do i do wrong?
In case it was not obvious yet, i am new in Struts 2, and dont know Struts, so please be patient

Thanks in advance
 
Ranch Hand
Posts: 349
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I believe I had the same problem you are have yesterday. I was able to get it to work by doing the following:



I wish I had an explanation for why this worked for me but I don't have a good understanding of what the process is that struts2 uses to populate arrays and ArrayLists from html forms. If anyone know a good place that describes this process, please let me know.
 
alberto vegas
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Tom,

Thanks for your reply, in fact i'm a step closer to get it thanks to your post, but unfortunatelly it's still not working completelly fine for me. With your code i can get my variable operationsSelected in my action class created with the proper size, but the values inside are null. If my collection is size=5, never mind how many checkboxes i select, my array String[] operationsSelected will be created size=5, but with null inside each position...

I'm still testing so if i can find out something, i'll post it here

Regards
 
alberto vegas
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
At the end i substituted the checkboxes with links "Remove"
Its a pity that i couldnt understand how to solve that, but it was getting too much time consuming

Regards!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic