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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T04:44:34+00:00 2026-06-05T04:44:34+00:00

i need your help as the title says i have a problem inserting multiple

  • 0

i need your help as the title says i have a problem inserting multiple rows from a jsp form. The code is from an answer from this site.

Controller

@ModelAttribute("programform")
public ProgramForm populatePojos() {
    // Don't forget to initialize the pojos list or else it won't work
    ProgramForm programform = new ProgramForm();
    List<Programs> programs = new ArrayList<Programs>();
    for(int i=0; i<2; i++) {
        programs.add(new Programs());

    }
    programform.setPrograms(programs);
    return programform;
}




@RequestMapping(value = "/createprog")
public ModelAndView tiles2(@ModelAttribute("programform") ProgramForm  programform,
        BindingResult result) {
    //Map<String, Object> model = new HashMap<String, Object>();
    //model.put("articles",  articleService.listArticles());

    return new ModelAndView("createprogram");
}


@RequestMapping(value = "/saveprogram", method = RequestMethod.POST)
public ModelAndView saveProgram(@ModelAttribute("programform") ProgramForm  programform,
        BindingResult result) {
    for(Programs programs : programform.getPrograms()) {
           System.out.println(programs.getProgram_id());
           articleService.addProgram(programs);
        }

jsp

 <c:url var="saveProgramUrl" value="/articles/saveprogram.html" />
<form:form modelAttribute="programform" method="POST" action="${saveProgramUrl}">
<table>
<tr>
            <th>ProgramId</th>
            <th>Date</th>
            <th>Type</th>
            <th>Start</th>
            <th>End</th>
            <th>Location</th>
            <th>User</th>
            <th>Program Name</th>
</tr>
    <tr> 
                <th><form:input path="programs[0].program_id" /></th>
                 <th> <form:input path="programs[0].date" id="datepick" class="date-pick"/>
        <script type="text/javascript">
            datepickr('datepick', { dateFormat: 'Y-m-d' });
        </script></th>
                <th><form:input path="programs[0].type" /></th>
                <th><form:input path="programs[0].start" /></th>
                <th><form:input path="programs[0].end" /></th>
                <th><form:input path="programs[0].location" /></th>
                <th><form:input path="programs[0].user_id" /></th>
                <th><form:input path="programs[0].program_name" /></th>
    </tr>
 <tr> 
                <th><form:input path="programs[1].program_id" /></th>
                 <th> <form:input path="programs[1].date" id="datepick" class="date-pick"/>
        <script type="text/javascript">
            datepickr('datepick', { dateFormat: 'Y-m-d' });
        </script></th>
                <th><form:input path="programs[1].type" /></th>
                <th><form:input path="programs[1].start" /></th>
                <th><form:input path="programs[1].end" /></th>
                <th><form:input path="programs[1].location" /></th>
                <th><form:input path="programs[1].user_id" /></th>
                <th><form:input path="programs[1].program_name" /></th>
    </tr>
</table>
<br/>
<input type="submit" value="Insert User" />
</form:form>

Program

    package net.roseindia.model;



import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name = "program")
public class Programs {




    @Id
    @Column(name = "Program_Id")
    private int program_id;
    @Column(name = "Date")
    private String date;
    @Column(name = "Duty_Type")
    private String type;
    @Column(name = "Duty_Start_Time")
    private String start;
    @Column(name = "Duty_End_Time")
    private String end;
    @Column(name = "Location")
    private String location;
    @Column(name = "User_Id")
    private int user_id;
    @Column(name = "Program_Name")
    private String program_name;


    public int getProgram_id() {
        return program_id;
    }


    public void setProgram_id(int program_id) {
        this.program_id = program_id;
    }


    public String getDate() {
        return date;
    }


    public void setDate(String date) {
        this.date = date;
    }


    public String getType() {
        return type;
    }


    public void setType(String type) {
        this.type = type;
    }




    public String getStart() {
        return start;
    }


    public void setStart(String start) {
        this.start = start;
    }


    public String getEnd() {
        return end;
    }


    public void setEnd(String end) {
        this.end = end;
    }


    public String getLocation() {
        return location;
    }


    public void setLocation(String location) {
        this.location = location;
    }


    public int getUser_id() {
        return user_id;
    }


    public void setUser_id(int user_id) {
        this.user_id = user_id;
    }


    public String getProgram_name() {
        return program_name;
    }


    public void setProgram_name(String program_name) {
        this.program_name = program_name;
    }


    public Programs() { 

    }





}

ProgramForm

package net.roseindia.model;

import java.util.List;

public class ProgramForm {



    private List<Programs> programs;

    public List<Programs> getPrograms() {
        return programs;
    }

    public void setPrograms(List<Programs> programs) {
        this.programs = programs;
    }


}

When i push the button to save this to programs nothing inserted in the database, what i am doing wrong?

  • 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-06-05T04:44:36+00:00Added an answer on June 5, 2026 at 4:44 am

    To add multiple rows you need to lazy init your list. Please change your code in the @ModelAttribute("programform") as per following and then try again.

    @ModelAttribute("programform") 
    public ProgramForm populatePojos() { 
        // Don't forget to initialize the pojos list or else it won't work 
        ProgramForm programform = new ProgramForm(); 
        List<Programs> programs = LazyList.decorate(new ArrayList<Programs>(), FactoryUtils.instantiateFactory(Programs.class));
    
        for(int i=0; i<2; i++) { 
            programs.add(new Programs()); 
    
        } 
        programform.setPrograms(programs); 
        return programform; 
    }
    

    With having list inilialized as above you can also add more fields run time using javascript and can get those values binded in your list.

    After doing this changes if it won’t work then you need to do changes in your jsp page. Instead of using the use simple tag but don’t forget to specify the same value in name attribute as you have specified in the path attribute here.

    Hope this helps you. Cheers.

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

Sidebar

Related Questions

I need your help to solve a silly problem. I have 2 tables in
I need your help with the textarea of my form fields. I have the
I really need your help since I have a frustrating problem. I'm downloading data
I need your help. I have a C executable called generator.out that is a
I need your help. I have made a really clean and simple example to
I need your help to optimize the query below. Let us assume we have
I need your help. I have tables using PHP while looping and I need
I really need your help: I have installed easphp on my laptop (apache, php,
Hey guys, I need your help. What can be my problem why its giving
I am just starting to learn js and need your help. I have following

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.