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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:36:34+00:00 2026-05-25T19:36:34+00:00

I need to validate the objects which are stored in the list on my

  • 0

I need to validate the objects which are stored in the list on my form bean object.

Below is my form bean object.

public class Role implements java.io.Serializable {

    // Fields    
    private int roleId;

    @NotBlank
    private String roleName;

    private boolean active;

    @Valid
    private List<Module> modules;

    // getters anfd setters
}

and below is my object which is present in the list of my main form bean object

public class Module implements Serializable {

    private int id;

    @NotBlank
    private String moduleName;

    // other properties and getters and setters
}

Below is my properties file

# -- Role form -- 
NotBlank.role.roleName=Role Name can not be blank.
NotBlank.module.moduleName=Module Name can not be blank.

Below is My JSP page, the form consists of a role name and modules which can be added to the role.

    <table border="0" class="section_tbl2">
    <tr>
        <td width="150px" valign="top">
            <spring:message code="dmx.role.form.label.name"/>
        </td>
        <td width="10px">:</td>
        <td>
            <form:input class="txtinput" id="roleName" path="roleName" maxlength="50"/>      <form:errors path="roleName" cssClass="error"/>

        </td>
    </tr>
    <tr><td colspan="3" height="8px"></td></tr>

    <tr>
        <td width="150px" vAlign="top">
            Modules
        </td>
        <td width="10px" vAlign="top">:</td>
        <td>

            <table>
                <tr>
                    <td>
                        <input type="button" value="<spring:message code="dmx.role.form.button.addModule.label"/>" onclick="return addModuleRow();"></input>
                    </td>
                </tr>
                <tr><td>&nbsp;</td></tr>
            </table>

            <table cellpadding="0" cellspacing="0" border="0" class="tblstyle1" id="moduleTable">
                <thead>
                    <tr>
                        <th class="fst" width="200px">
                            <spring:message code="dmx.role.form.label.moduleName"/>
                        </th>
                        <th width="50px"><spring:message code="dmx.role.form.label.create"/></th>
                        <th width="50px"><spring:message code="dmx.role.form.label.update"/></th>
                        <th width="50px"><spring:message code="dmx.role.form.label.delete"/></th>
                        <th width="30px"></th>
                    </tr>
                </thead>
                <tbody id="moduleTBody">
                    <c:forEach items="${role.modules}" var="module" varStatus="status" >
                        <c:set var="moduleCounter" value="${status.index}"/>
                        <tr id="moduleRowId_${moduleCounter}">
                            <td class="fst txt-center">
                                <form:select onchange="checkIfThisModuleAlreadySelected(this);" class="seloption" id="selectedModule_${moduleCounter}" path="modules[${moduleCounter}].id">
                                    <form:option value="" label="-- Select Module --"/>
                                    <form:options items="${moduleList}" itemLabel="moduleName" itemValue="id" />
                                </form:select>
                            </td>
                            <td class="txt-center">
                                <form:checkbox id="create_${moduleCounter}" path="modules[${moduleCounter}].create"/>
                            </td>
                            <td class="txt-center">
                                <form:checkbox id="update_${moduleCounter}" path="modules[${moduleCounter}].update"/>
                            </td>
                            <td class="txt-center">
                                <form:checkbox id="delete_${moduleCounter}" path="modules[${moduleCounter}].delete"/>
                            <td class="txt-center">
                                <input class="delbtn" id="moduleDelBtn_${moduleCounter}" name="moduleDelBtn[${moduleCounter}]" type="button" onclick="delModuleRow(${moduleCounter});">
                            </td>
                        </tr>
                    </c:forEach>
                </tbody>    
            </table>                
        </td>
    </tr>
    <tr><td colspan="3" height="3px"></td></tr>
</table>

I can successfully validate the role name i.e. when role name is blank I get an error message but when module is not selected i do not get any error message.

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-25T19:36:35+00:00Added an answer on May 25, 2026 at 7:36 pm

    Adding @NotNull and @Size constraints to your module list should help:

    @Valid
    @NotNull
    @Size(min = 1)
    private List<Module> modules;
    

    The @Valid annotation causes the elements of the annotated collection to be validated but it doesn’t validate wether that collection is not null or contains any elements.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an object which i need to validate. This object has properties which
I need to validate this simple pick list: <select name=<%= key %>> <option value=ETC
I have a limited set of objects (20 - 30) which I need to
I have an object which I must validate values off the problem, some of
I need to validate a date/time field on a webpage but want it to
I need to validate an XML string (and not a file) against a DTD
I need to validate the email address of my users. Unfortunately, making a validator
I need to validate a certain property to one of my classes. When I
I need to validate the user input of a JSpinner , and if invalid,
I need to validate an XML agaist a schema. I tried XML::SAX::ParserFactory; XML::Validator::Schema and

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.