Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6196435
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:38:37+00:00 2026-05-24T03:38:37+00:00

I have dynamic number of checkboxes in jsp page as given below. <s:iterator value=details

  • 0

I have dynamic number of checkboxes in jsp page as given below.

<s:iterator value="details"  status="stat">
         <s:checkbox name="checkbox"  theme="simple" />
         <s:hidden name="hidden" value="%{top}" /> 
</s:iterator>

Let’s say 4 checkboxes.

and setter in action class is

public void setCheckbox(boolean s[])
{
    System.out.println(s.length);
}

If I don’t select any checkbox, s.length is zero.
If I select 3rd checkbox, s.lenght is 1 and it is initializing s[0] with true.
But problem is here how can I find whether 3rd checkbox is selected or another checkbox is selected.

I thought that setter would initialize s[]={false,false,true,false}, if I select third checkbox. But it is initializing s[]={true}.

Corresponding hidden values of those selected boxes are required to perform required action in database. But for that I need to find select checkboxes.
Please suggest me any solution.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T03:38:37+00:00Added an answer on May 24, 2026 at 3:38 am

    Because your checkboxes are all named the same (checkbox), Struts2 is just passing the following:

    checkbox=true&checkbox=true&checkbox=true

    Does that mean that you omitted the second, third, or fourth checkbox?

    What you actually want is not an array of booleans, but a map of Integer to Boolean. Here’s an example:

    Example Action

    public class MyAction extends ActionSupport {
      private Map<Integer, Boolean> checkboxes;
    
      ...
    
      public Map<Integer, Boolean> getCheckboxes() {
        return checkboxes;
      }
    
      public void setCheckboxes(Map<Integer, Boolean> checkboxes) {
        this.checkboxes = checkboxes;
      }
    }
    

    Example JSP

    <s:iterator value="details" status="stat">
      <%-- this outputs checkboxes[0], checkboxes[1], etc. --%>
      <s:checkbox name="checkboxes[%{#stat.index}]"  theme="simple" />
    </s:iterator>
    

    Example Result

    • 0 -> true
    • 1 -> false
    • 2 -> true
    • 3 -> true
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have dynamic page. There are multiple checkboxes & I am using this script
I have these dynamic checkboxes each with ID + number +1. Could anyone tell
I have an HTML form with a dynamic number of checkbox fields, all of
I have a page which contains a dynamic number of custom WebControls. What I
I have a page that loads a dynamic number (however many in the database
I have a a gridview with a dynamic number of columns and rows. In
I have a form with a stage that has a dynamic number of groups
I have dynamic web page with JS. There is a <textarea> and a Send
Is it possible to have a dynamic number of series for a WPF toolkit
I have an web application with a dynamic number of tabs ranging between 2

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.