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

  • SEARCH
  • Home
  • 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 7502015
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T20:43:39+00:00 2026-05-29T20:43:39+00:00

Hello guys Im currently itearing over a list and im hard-coding fieldsets based on

  • 0

Hello guys Im currently itearing over a list and im hard-coding fieldsets based on if they match a certain criteria. How can I write a loop that creates a fieldset based off all the groupnames in the lidst and populates that fieldset with all the corresponding displayNames that go along with that groupName dynamically. Im currently hardcoding this.

<%@ include file="../include/pre-header.html" %>

    <tr>
        <th>
            <span onclick="toggleDiv('displayFields', 'displayImg')" style="cursor: hand;">Data Fields&nbsp;<img name="displayImg" src="../images/minus.gif" /></span>
        </th>

    </tr>

    <tr>
        <td>

            <div id="displayFields" style="display:block;">
            <fieldset class="det">
                <legend>Header Data</legend>
                    <c:forEach var="detBean" items="${detFields}">
                        <c:if test="${detBean.groupName == 'HEADER_DATA'}">
                    <input type="checkbox" name="fieldNames" value="${detBean.fieldName}">${detBean.displayName}</input>
                            <br/>
                        </c:if>
                   </c:forEach>
            </fieldset>

            <fieldset class="det">
                <legend>Materiel Data</legend>
                    <c:forEach var="detBean" items="${detFields}">
                        <c:if test="${detBean.groupName == 'MATERIEL_DATA'}">
                    <input type="checkbox" name="fieldNames" value="${detBean.fieldName}">${detBean.displayName}</input>
                            <br/>
                        </c:if>
                    </c:forEach>
            </fieldset>

            <fieldset class="det">
                <legend>Planned Unit Data</legend>
                    <c:forEach var="detBean" items="${detFields}">
                        <c:if test="${detBean.groupName == 'PLANNED_DATA'}">
                    <input type="checkbox" name="fieldNames" value="${detBean.fieldName}">${detBean.displayName}</input>
                            <br/>
                        </c:if>
                    </c:forEach>
            </fieldset>

            <fieldset class="det">
                <legend>Actual Unit Data</legend>
                    <c:forEach var="detBean" items="${detFields}">
                        <c:if test="${detBean.groupName == 'ACTUAL_DATA'}">
                <input type="checkbox" name="fieldNames" value="${detBean.fieldName}">${detBean.displayName}</input>
                            <br/>
                        </c:if>
                </c:forEach>
            </fieldset>

            <fieldset class="det">
                <legend>Planned Cost Data</legend>
                <c:forEach var="detBean" items="${detFields}">
                    <c:if test="${detBean.groupName == 'COST_DATA'}">
                        <input type="checkbox" name="fieldNames" value="${detBean.fieldName}">${detBean.displayName}</input>
                        <br/>
                    </c:if>
                </c:forEach>
            </fieldset>

            <fieldset class="det">
                <legend>Carry Over Data</legend>
                    <c:forEach var="detBean" items="${detFields}">
                        <c:if test="${detBean.groupName == 'CARRYOVER_DATA'}">
                    <input type="checkbox" name="fieldNames" value="${detBean.fieldName}">${detBean.displayName}</input>
                        <br/>
                        </c:if>
                    </c:forEach>
            </fieldset>

            <fieldset class="det">
                <legend>Schedule Exceptions</legend>
                    <c:forEach var="detBean" items="${detFields}">
                        <c:if test="${detBean.groupName == 'SCHEDULE_EXCEPTIONS'}">
                    <input type="checkbox" name="fieldNames" value="${detBean.fieldName}">${detBean.displayName}</input>
                        <br/>
                        </c:if>
                    </c:forEach>
            </fieldset>

            <fieldset class="det">
                <legend>DIFMS data</legend>
                    <c:forEach var="detBean" items="${detFields}">
                        <c:if test="${detBean.groupName == 'DIFMS_DATA'}">
                    <input type="checkbox" name="fieldNames" value="${detBean.fieldName}">${detBean.displayName}</input>
                        <br/>
                        </c:if>
                    </c:forEach>
            </fieldset>
            </div>
            <tr>
            <td style="text-align: center;">
            <input type="button" name="clear_choice"  value="Check All" onclick="checkUncheck(true);"/>
            &nbsp;&nbsp;&nbsp;&nbsp;
            <input type="button" name="clear_choice"  value="Uncheck All" onclick="checkUncheck(false);"/>

            </td>
            </tr>

        </td>
        </tr>
  • 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-29T20:43:40+00:00Added an answer on May 29, 2026 at 8:43 pm

    I’d suggest to change your datastructure from List<DetBean> to Map<String, List<DetBean>> where the group name is the map key.

    The below example shows how to convert it:

    Map<String, List<DetBean>> detFieldMap = new LinkedHashMap<String, List<DetBean>>();
    
    for (DetBean detBean : detFields) {
        String groupName = detBean.getGroupName();
        List<DetBean> detBeans = detFieldMap.get(groupName);
    
        if (detBeans == null) {
            detBeans = new ArrayList<DetBean>();
            detFieldMap.put(groupName, detBeans);
        }
    
        detBeans.add(detBean);
    }
    
    request.setAttribute("detFieldMap", detFieldMap);
    

    (you can of course also change the datastructure at the point where you’re creating the original detFields list)

    You probably also want to maintain a mapping of all header names

    Map<String, String> detFieldHeaders = new HashMap<String, String>();
    detFieldHeaderMap.put("HEADER_DATA", "Header Data");
    detFieldHeaderMap.put("MATERIEL_DATA", "Materiel Data");
    // ...
    
    request.setAttribute("detFieldHeaders", detFieldHeaders);
    

    (it would probably be better to create it once on webapp’s startup and store in application scope, you can use a ServletContextListener for this)

    This way you can use a single nested <c:forEach>. Every iteration over a Map gives Map.Entry back which in turn has getKey() and getValue() methods. The key is then the String group name and the value is then the List<DetBean>.

    <c:forEach items="${detFieldMap}" var="detFieldEntry">
        <fieldset class="det">
            <legend>${detFieldHeaders[detFieldEntry.key]}</legend>
            <c:forEach items="${detFieldEntry.value}" var="detBean">
                <input type="checkbox" name="fieldNames" value="${detBean.fieldName}">${detBean.displayName}</input>
                <br/>
            </c:forEach>
        </fieldset>
    </c:forEach>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello guys I am currently parsing all the html body for finding the document
Hello guys I need to pass a string array over to a setter that
hello guys recently i joined a company. They assigned me a task is to
hello guys i am doing some database operations in iphone .. please can anyone
Hello guys can you please help me with this problem. When a simple image
PLEASE READ THE FULL QUESTION BEFORE POST YOUR ANSWER Hello guys! I'm currently developing
Hello guys I newbie question :) - I am currently using PHP/Zend and now
hello guys can i ((turn my phone on)) from specific message ??? and if
Hello guys first of all apologize for asking such a simple and yet redundant
Hello guys sorry if the question looks stupid to you. i have 3 tables

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.