File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes How to make checkbox checked in display tag Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How to make checkbox checked in display tag" Watch "How to make checkbox checked in display tag" New topic

How to make checkbox checked in display tag

Raaja Gotluru
Ranch Hand

Joined: Mar 02, 2010
Posts: 118

I am using struts framework and in the jsp I am having display table like below.

<display:table id="data" name="deptUsers" requestURI="/"
pagesize="10" cellpadding="2" cellspacing="2" decorator="com.krishct.efiler.user.documents.DownloadDecorator">
<display:column property="branch" title="Branch" sortable="true" style="text-align:center;" />
<display:column property="loginId" title="User Name"sortable="true" style="text-align:center;" />
<display:column title="View" style="text-align:center;">
<html:checkbox name="deptUsers" property="view" />
<display:column title="Review" style="text-align:center;">
<html:checkbox name="deptUsers" property="review" />

But this is not working.

I want the checkboxes get selected if the value from the database is true and others unchecked and if I select some other check boxes in different pages of the table and submit them they should be stored in database.

How to achieve this please guide me.

Rajagopal Mani
Ranch Hand

Joined: Mar 24, 2011
Posts: 84


The bean class should have boolean property like "isChecked" and setter,getter pair as well. The value attribute will be assigned with unique loginid(please use if have some other unique id) for each checkbox. In selectUser() JS function, you can have logic for maintain the selected checkbox list. On submit form, the selected checkbox list(means uniqueid list) can be set in hidden field and obtain in action class. Below are the code snippets

In case of <input type="checkbox">

I agree. Here's the link:
subject: How to make checkbox checked in display tag
It's not a secret anymore!