Pages Navigation Menu

Coding is much easier than you think

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

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.


<display:table name="productList" pagesize="10" requestURI="productAction" id="row">

<display:column title="Delete">
<s:checkbox name="productList[%{#attr.row_rowNum - 1}].chkBox" 
  id="check%{#attr.row_rowNum - 1}" value="%{#attr.row.chkBox}"/>

<display:column property="product" title="Product Name"/>
<display:column property="price" title="Price"/>

<s:submit action="removeProduct" value="Delete"
  onClick="return confirm('Do you want to delete these items?');"/>

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

About Mohaideen Jamil

Am currently working as a Struts 2 Developer in a reputed IT Organisations. I can help you with teaching Core java and Struts 2. Follow me on Facebook or Google Plus. If you like my tutorials, consider making a donation to this charity, thanks.

  • ramanareddy moole

    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.


    Ramana Reddy

  • alex


    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 ?


  • Gözde Aldikacti

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

  • Thakur Shardendu Singh Butola

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

  • shivesh

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

  • rajibkumarmohanty

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