How to display properties of specific object selected via dropdown?

Viewed 19

I wrote a query in which I get the semester class, display its values ​​as a name and get its id. Accordingly, when I select the semester I need in the drop-down list, I am given the semester that I chose. But I also need to display its duration in another field, I can do this if I create a ForEach loop and use it to extract this value, but it displays absolutely all the available values, and not the one I need. Tell me how to do it right? For display I use Spring MVC. Now the page looks like this:

enter image description here

I am also attaching the jsp content:

<form:form action="allSemestrsSem" method="get" id="selectSemestr" modelAttribute="semestr">
  <tr>
    <td style="font-size: large;">Select semester</td>
    <td style="padding-left: 50px">

      <select name="selectSemestr">

        <c:forEach items="${semestr}" var="semestr">
          <option value="${semestr.id}">${semestr.name}</option>
        </c:forEach>

      </select>
    </td>
    <td style="padding-left: 20px">
      <security:authorize access="hasRole('ADMIN')">
        <input type="submit" id="button" value="select" /></td>
    </security:authorize>
  </tr>

  <tr height="80px" style="font-size: large; font-weight: bold;">
    <td colspan="3">Semester duration:
      <c:forEach items="${semestr}" var="semestr"> ${semestr.duration} </c:forEach>
    </td>
  </tr>

</form:form>

And just in case my controller is:

@RequestMapping(value = "/allSemestrsSem", method = RequestMethod.GET)
public String allSemestrs(@RequestParam(name = "selectSemestr") String selectSemestr, Model model) {
    List<Semestr> semestr = service.getSemestr();
    model.addAttribute("semestr", semestr);
    List<Discipline> allDisciplines = service.getDisciplineSemestrId(Integer.valueOf(selectSemestr));
    model.addAttribute("allDisc", allDisciplines); 
    return "semestr";
}
0 Answers
Related