I have a search function that returns an arraylist of objects to my form. I am iterating through the list using JSTL’s foreach tags.
<c:forEach items="${searchResults}" var="contact" varStatus="loop">
<div style="padding: 5px;">
${contact.firstName} ${contact.lastName}
<br>
${contact.primaryPhone}
<br>
//Is this the proper way to set up the url?
<a href="Contacts?search=${param.search}&id=${loop.index}">View Contact</a>
</div>
<br>
</c:forEach>
When the user clicks the link inside each row, the row index is passed to the querystring and at this point I would like to show a div that contains additional information about the user.
I have a javascript function that I use to display the div and center it on the screen bla bla bla, but my question is how do I refresh the page with the index loaded into the querystring and then fire my javascript function?
I considered using:
<c:if test="${not empty param.id}">
//Check if id in querystring is available and if so, display popup
</c:if>
To check if there was an index available in the querystring, but I don’t think there is a way to fire my function from within a JSTL tag.
Should I be doing something on the server side when I request back to the servlet rather than trying to handle this on the client side? I just figure its a waste to requery my database and set another request parameter, when I already have the information I need stored in a parameter than I am using to display my list anyways.
The solution I eventually came up with is to check for my id parameter in the querystring each time the page loads (with javascript)
The function I use to check the querystring is: