Context
Legacy system written in Java Server pages 2.
Problem
I have a managed bean that provides a list of students (StudentListBean
) to a page (student-list.xhtml
). This bean does not provide access to a single student, since its goal is to generate a student listing and it's working correctly for that purpose. Each student is shown in a data table, that iterates along the students collection.
Some students have a certain condition that may require to show some details. In these cases, a link is provided so the user can click and see those details.
The link is correctly built when it has to be shown, but since those details can be very large, those should be shown in another tab in the browser, not in the same one showing the listing. So, the new page will show data from a single student.
Because StudentListBean
does not expose a single student, it cannot be used to show data from a single student. Changing its behavior is considered a bad choice because the bean intends to manage a collection of students, not a single one. A new bean (StudentBean
) is to be created to provide access to all the details of a single student.
The question here is: what to do to pass a student's Id
(the current one in the listing) to the StudentBean
so it can load the student from its Id
and so its data can be shown in another page (student.xhtml
)?
Since no interaction is need with StudentListBean
, the link was build using <h:link/>
tag, because some online sources suggested that it's a more efficient choice to <h:commandLink/>
.
Thanks in advance!