Pages Navigation Menu

Coding is much easier than you think

How to get checkbox values from struts2 checkbox in displaytag to action class

 
Consider a scenario, such that we have a list of items and each item can be selected by checking its checkbox. If a submit button is clicked after selecting all necessary checkboxes. So now, in our Action class, we could get the values of checkboxes which had been selected, by which we can implement delete functionality.
 
** UPDATE: Struts 2 Complete tutorial now available here.
 

The following snippet of code is used to retrieve the value from a checkbox used inside displaytag.

 

 

 
In our Action class, we can get the values of checkbox by creating getter & setter for the field “chkBox”.
 

6 Comments

  1. Hi Jamil,

    To the same code above, I am adding sorting using sortable attribute. For me this works only in first page. When navigated to second or other pages, it doesn’t work. Please help me.

    Code:

    Regards
    Ramana Reddy

  2. Hi,

    In the HTML page I’m getting a generated component name like : xxx_productList[n].chkBox_xxx, n being the row number. But from the 1000th record the row number is getting formatted with thousand separator (ie. generates a component name like : xxx_productList[1 000].chkBox_xxx) which makes the component not working.
    Tried to modify the regional setting on my PC but it doesn’t help.

    Do you have any idea ?

    tks,

  3. I cannot get checkbox value in action class. It comes as null. Can you explain clearly the action class part?

  4. i am getting only the check boxes value ..while also want the value of other attributes to get in my action class

  5. How to use checkBox or radio button inside list or iterator . please help..

  6. Can you please post “File download based on Checkbox selection ”

    Thanks