jsp (jstl 1.2) - set a variable from a java list -


(i using jstl version 1.2 , java 6)

i working legacy code has logic in jsp pages, aside need loop on list of data, match on , set variable list value (arraylist in case). reason need loop on list found later on in jsp file.

here snippet of code have far, not work:

  <c:set var="listofchilddata" value="${[]}" scope="page"/>    <c:foreach items="${otherlistofdata}" var="data">      <c:if test="${data.id == datatomatchon.id}">        <c:catch var="exception">${data.children}</c:catch>       <c:if test="${empty exception}">          <c:set var="listofchilddata" value="${data.children.toarray()}" scope="page"/>        </c:if>     </c:if>   </c:foreach> 

do need manually go through each item in list , add listofchilddata?

reading around, examples found of creating array variable scratch , not variable.

if comes down using scriptlets, can within foreach loop?


updated include exception handling if data.children null, empty, etc.

you don't need copy list. need set selecteditem , can work this:

<c:foreach items="${otherlistofdata}" var="data">     <c:if test="${data.id == datatomatchon.id}">         <c:set var="selecteditem" value="${data}/>     </c:if> </c:foreach>  <p>from here on can work selected item:</p>  ${selecteditem.children} 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -