0

Just a quick simple ish query, I would imagine.

public class TimetableV1 implements Timetable {

    @Id
    @GeneratedValue
    private int id;

    @Size(min=5, max=10, message="Court must be between 5 and 10 characters",groups={PersistenceValidationGroup.class, FormValidationGroup.class})
    private String name;

    @NotNull
    private int slots;

    private int startTime;

    private int endTime;

    @ElementCollection
    @CollectionTable (name = "monday", joinColumns=@JoinColumn(name="id"))
    List<String> monday;

    @ElementCollection
    @CollectionTable (name = "tuesday", joinColumns=@JoinColumn(name="id"))
    List<String> tuesday;

    @ElementCollection
    @CollectionTable (name = "wednesday", joinColumns=@JoinColumn(name="id"))
    List<String> wednesday;

    @ElementCollection
    @CollectionTable (name = "thursday", joinColumns=@JoinColumn(name="id"))
    List<String> thursday;

    @ElementCollection
    @CollectionTable (name = "friday", joinColumns=@JoinColumn(name="id"))
    List<String> friday;

    @ElementCollection
    @CollectionTable (name = "saturday", joinColumns=@JoinColumn(name="id"))
    List<String> saturday;

    @ElementCollection
    @CollectionTable (name = "sunday", joinColumns=@JoinColumn(name="id"))
    List<String> sunday;


//getters
    }

I have that class, which is working great, in terms that I have it reading and writing with Hibernate.

Here's the relevant test from my Controller.

@RequestMapping("/timetable")
    public String showTimetable(Model model) {
        MonaleenTTV1 t = new MonaleenTTV1();
        t.setName("Test Timetable");
        t.setSlots(9);
        t.setStartTime(1);
        t.setEndTime(2);
        for (int i = 0; i < t.getSlots(); i++){
            t.getMonday().add("Monday" + i);
            t.getTuesday().add("Tuesday" + i);
            t.getWednesday().add("Wednesday" + i);
            t.getThursday().add("Thursday" + i);
            t.getFriday().add("Friday" + i);
            t.getSaturday().add("Saturday" + i);
            t.getSunday().add("Sunday" + i);
        }
        timetableService.create(t);
        List<String> monday = t.getMonday();
        List<String> tuesday = t.getTuesday();
        List<String> wednesday = t.getWednesday();
        List<String> thursday = t.getThursday();
        List<String> friday = t.getFriday();
        List<String> saturday = t.getSaturday();
        List<String> sunday = t.getSunday();
        model.addAttribute("monday", monday);
        model.addAttribute("tuesday", tuesday);
        model.addAttribute("wednesday", wednesday);
        model.addAttribute("thursday", thursday);
        model.addAttribute("friday", friday);
        model.addAttribute("saturday", saturday);
        model.addAttribute("sunday", sunday);


        return "timetable";
    }

Everything works fine, but when I display the model for each item, I'm getting a list like this.

[Monday0, Monday1, Monday2, Monday3, Monday4, Monday5, Monday6, Monday7, Monday8]

Is there a way to split this so I can use it as something like

<table>
<tr>Monday0</tr>
<tr>Monday1</tr>
<tr>Monday2</tr>
</table>

Currently, my jsp code for it is this.

<table class="members">
    <tr><td>${tuesday}</td></tr>
</table>

I had this but it just repeated the list each time for the number of attributes.

<table class="members">
    <c:forEach var="row" items="${sunday}">
    <tr><td>${sunday}</td></tr>
    </c:forEach>
</table>

1 Answer 1

2

You have to change sunday to row inside forEach:

<table class="members">
    <c:forEach var="row" items="${sunday}">
    <tr><td>${row}</td></tr>
    </c:forEach>
</table>
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! That did the job! I'll accept this answer once it lets me!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.