How to retrieve a variable name given its value?

How can I filter the result given by c:for each using the value selected in a drop down without going to back end?

  • Following is my jsp code. <c:forEach items="${nameList}" var="studentList"> <tr> <td style="padding-bottom: .5em;"> <a id="student" href="number?regNo=<c:out value="${studentList.regNo}"/>"> <span class="eachStudent"> <span class="studentName"><c:out value="${Page on studentlist.name}"/></span><br/> <span class="collName"><c:out value="${studentList.collName}"/></span><br/> <span class="deptName"><c:out value="${studentList.deptName}"/></span><br/> </span> </a> </td> </tr> </c:forEach> The above c:forEachc:forEachc:forEach lists Name CollName DeptName ABCD coll1 dept1 kfkdb coll1 dept2 jbdd coll2 dept3 Following is the code that lists the collNamecollNamecollName and deptNamedeptNamedeptName respectively. <div> Filter students by College (not required): <select id="byCollege" name="byCollege" > <c:forEach items="${uniqueCollList}" var="uniqueCollList"> <option value="${uniqueCollList}"/> ${uniqueCollList}</option > </c:forEach > </select > </div> <div> Filter students by Department Name (not required): <select id="byDept" name="byDept" > <c:forEach items="${uniqueDeptList}" var="uniqueDeptList"> <option value="${uniqueDeptList}"/> ${uniqueDeptList}</option > </c:forEach > </select > </div> Now when I select a value from first dropdown, I want to filter the results given by foreachforeachforeach using the value selected in dropdown. I would like to do this in front end itself, rather going to the back end. May I know how can I do this? After filtering the c:foreachc:foreachc:foreach result using value of first dropdown, if I select a value in second dropdown, I want the updated result of c:foreachc:foreachc:foreach to  be filtered using the value selected in second drop down. How can I do this? If I want to do this in back end, what should I do?

  • Answer:

    The proper solution for this type of requirement is to let the back end serve up JSON content, then render the table in the front end in JavaScript. This is a common pattern with JavaScript frameworks. With Spring, Spring MVC can create the JSON. Without making this change, the solution will be inelegant and possibly buggy. The select element would need to trap the changes in the selection then show or hide the elements in the table based. It may also be possible to redraw the entire table but that is not feasible because the JavaScript code does not have the data structure that the table represents - it can only scrape off the element data from the .

Miguel Paraz at Quora Visit the source

Was this solution helpful to you?

Other answers

Take one variable isSelected=false Now when user select any value from dropdown make it true. While iterating place if else check for variable and display only required value. hope you can get code snippet on http://stackoverflow.com

Deepak Pandey

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.