I am working on the frontend of a project that gives me Java Expression Language tags to work with. In one instance I need to see if it is returning an array or just one bit of data and I don’t know how to work with it.
Example:
The page has
<p>${WebAppContext.buildings[0].location.name}</p>
which will output something like:
<p>Acme</p>
Problem is I need to output more if there is more in that buildings bit:
Something like (in pseudocode):
if isArray(${WebAppContext.buildings}){
foreach(${WebAppContext.buildings} as foo){
//iterate over whatever is in the array
}
}
so I can output something like:
<p>${WebAppContext.buildings[0].location.name}</p>
<p>${WebAppContext.buildings[1].location.name}</p>
I asked the Java people responsible for generating this code and they said “Dunnokindofbusyrightnowbuhbye.” so I’m hoping you folks will have some insight.
Beyond sticking the code in the page I don’t have a clue how to work with this Java Expression Language (I even had to look it up to see what the heck it is called). So any advice/resources would be helpful.
EDIT:
I’ve tried the following and am not getting any results:
<c:forEach var='building' items='${WebAppContext.buildings}'>
<p>${building.location.name}</p>
</c:forEach>
In the source of the page it just shows:
<c:forEach var='meeting' items='[Lorg.foo.bar.baz.bat.serviceapi.webserviceobject.xsd.BuildingsWSO;@3823ff8'>
<p></p>
</c:forEach>
I’ll admit that, not knowing anything about Java Expression Language, I don’t understand why the items=” gets translated like it does though I can see that it follows a path in the setup we use.
Now when I use:
<p>${WebAppContext.buildings[0].location.name}</p>
<p>${WebAppContext.buildings[1].location.name}</p>
I get:
<p>Krustylu Studios</p>
<p>Springfield Nuclear Power Plant</p>
I don’t think that kind of advanced functionality is supported by EL; you can try using the JSTL c:forEach tag to iterate over your list.