Dismiss
Announcing Stack Overflow Documentation

We started with Q&A. Technical documentation is next, and we need your help.

Whether you're a beginner or an experienced developer, you can contribute.

Sign up and start helping → Learn more about Documentation →


I'm working on an "absence management" web app using AngularJS and Spring MVC.
In my JSP, i used AngularJS to retrieve a specific students.
I want to select the absent students and add, for each one of them, an absence instance in the DB.
I have two classes : Student.java, Absence.java.

@Entity
@Table(name = "STUDENT")
public class Student {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "ID_STUDENT")
    private Long idStudent;

    @Column(name = "NAME")
    private String name;

    @OneToMany(cascade = CascadeType.ALL)
    @JoinColumn(name = "idStudent")
    private List<Absence> absences = new ArrayList<Absence>();

    //getters & setters...
}

@Entity
@Table(name = "ABSENCE")
public class Absence {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "ID_ABSENCE")
    private Long idAbsence;

    @Column(name = "ABSENCE_DATE")
    private Date absenceDate;

    //getters & setters...
}

Here is my JSP :

<form method="post" action="/absences/add">
    <table>
        <thead>
            <tr>
                <th>#</th>
                <th>Student</th>
            </tr>
        </thead>
        <tbody>
            <tr ng-repeat="student in students">
                <td>
                    <input type="checkbox" name="StudentsIds[]" value="{{student.idStudent}}" />
                </td>
                <td>{{student.name}}</td>
            </tr>
        </tbody>
    </table>
    <input type="date" name="absenceDate" />

    <input type="submit" value="Submit"/>
</form>

I searched online and tried multiple stuff but nothing seems to work.
Thank you in advance!

EDIT 1:
I tried this in my controller, but i'm having a rough time trying to add multiple absences ...

@RequestMapping(value = "/absences/add", method = RequestMethod.POST)
public String addAbsence(@RequestParam(studentsIds[]) Long [] studentsIds, Absence[] absences) {
    //It seems there is a problem with "Absence[] absences" ...
    return "listAbsences";
}
share|improve this question
1  
What did you try? I don't see any back end code handling the /absences/add endpoint. – Robert Moskal Jun 29 '15 at 16:25
    
Using StudentsIds[] i get the IDs of all the students that i selected. I don't know how to do the same with Absence [].... – bboulahdid Jun 29 '15 at 16:36

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.