0

Displaying JSP page in spring MVC with server data, I'm sending data from spring to JSP page and based on the data object value need to unhide another row.

Part of my JSP page:

<tr>
    <td align="center"><select style="width: 300px" id="menu6" name="menu6" size=10 multiple>
        <c:forEach var="categoryTwo" items="${dataObj.categorySubcategoryNameAndIds}" >
            <option value="${categoryTwo.categoryTypeId}" categoryType="${category.categoryTypeId}" >${categoryTwo.feedCategoryOrSubCategoryName}</option>
        </c:forEach>
    </select><br /></td>
</tr>

<tr id="newRow" style="display: None">
    <td>
        something to show
    </td>
</tr>

The data which is displayed is coming from the server and is a list of object , based on the value of one the object member i.e categoryType(int variable) i have to unhide the row with id='newRow'.

problem is, i'm not able to figure out the way to push the categoryType Value to a javascript function.

The value of categoryType should be 5 to unhide the row with id='newRow'

  • You're asking how to pass server data to JavaScript. Multiple ways to do that (load JSON for instance). If this is about a single boolean value, just output `` in your JSP code. It should be noted that unless you also want your JS to be able to show or hide the row based on user interaction, you can simply use conditional rendering in your JSP code. Forget about "display: none" and JS, just either print the row to your HTML or don't, depending on the category type or whatever. –  Mar 04 '21 at 08:43
  • Ok, I think I completely misunderstood the question. Are you asking how to show/hide some element when the user makes a selection from a . –  Mar 04 '21 at 08:47
  • No no, @ChrisG , if the categoryType value is 5, i have to unhide the row with id='newRow', but the value 5 is coming from server and loaded in HTML. – Sriram Arvind Lakshmanakumar Mar 04 '21 at 09:15
  • Ok, so you have to dynamically hide/unhide the row based on the user's selection? In that case please provide example HTML, not JSP source. –  Mar 04 '21 at 09:18
  • hmm .. actually, the html code, which i have given is all there is. there is no user selection, data from server -> html -> check the data of the server -> hide/unhide. – Sriram Arvind Lakshmanakumar Mar 04 '21 at 09:23
  • Ok, so no user selection. In your JSP template you're looping over an array using `c:foreach`. As far as I understand, for some of these items, `category.categoryTypeId` is 5? And you want to display the new row if at least one of them has that value? Still, if there is no user interaction, then *you do not need JS*. You just output the row (or don't output the row) on the server, using JSP conditional rendering: https://stackoverflow.com/questions/5935892/if-else-within-jsp-or-jstl –  Mar 04 '21 at 09:27

0 Answers0