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 6875435
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:19:23+00:00 2026-05-27T04:19:23+00:00

I am writing a small web app using servlets and JSP ( no additional

  • 0

I am writing a small web app using servlets and JSP ( no additional frameworks ).

There is a page that displays all groups in the DB. There is a possibility to edit the entry, by pressing a button that will redirect to page "editGroup?id=1". So, the target serlvet finds to group with the provided id, populates the request with that bean and make a forward to a JSP page:

        <form action="addGroup.html" method="post">
            Group name : <input type="text" name="name" value="${group.name }"/><br /> 
            Group description : <input type="text" name="description" value="${group.description }"/><br /> 
            Group roles :
            <c:forEach var="role" items="${roles}">
                <input type="checkbox" name="roles_id" value="${role.id}" />${role.name}<br />
            </c:forEach>
            <input type="submit" value="Submit">
        </form>

The question is : how to preselect the roles that already are attached to the group ?
The group’s bean has a list of beans Role. The request also has set an attribute that store the list of all available roles.

So inside of the loop I need to check if that role is already attached to the edited group.

Please help.

  • 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-27T04:19:23+00:00Added an answer on May 27, 2026 at 4:19 am

    After some investigations I found the solution in this question:

    <c:forEach var="role" items="${roles}">
        <c:choose>
            <c:when test="${group.roles.contains(role)}">
                <input type="checkbox" name="roles_id" value="${role.id}" checked="checked"/>${role.name}
            </c:when>
            <c:otherwise>
                <input type="checkbox" name="roles_id" value="${role.id}"/>${role.name}
            </c:otherwise>
        </c:choose>
    </c:forEach>
    

    Using expression like : ${group.roles.contains(role)}

    or this way (thank you, BalusC ! )

    <c:forEach var="role" items="${roles}">
        <input type="checkbox" name="roles_id" value="${role.id}" ${group.roles.contains(role) ? 'checked' : ''}/>${role.name}      
    </c:forEach>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently writing a small web app using Asp.net MVC and jQuery mobile.
I'm writing a small web app that will receive and parse tab-delimited text files
I'm in the process of writing a small web app that would allow me
I am writing a small app that retrieves some html from a web server
I'm writing a small web server in Python, using BaseHTTPServer and a custom subclass
I'm writing a small web that just makes some animation and shows some information
I'm writing a small web server for testing purposes using python, BasicHTTPServer and SimpleHTTPServer.
I'm writing a small web app for myself in Rails and I want it
I'm writing a small non-commercial web app, and I'm wondering how to pass data
I am developing a small web app that internally authenticates users. Once the user

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.