0

I've been given a task to refactor a JSP project, and the last time I coded for JSP was in 2005, a time when we used much more scriptlets, and - AFAIK - there were no Expression Language.

The current page snippet I'm facing is this:

<c:if test="${value.prepphase.exists}">
<div>${value.prepphase.value.status}</div>
<div>${value.prepphase.value.eta}</div>
</c:if>

<c:if test="${value.initphase.exists}">
<div>${value.initphase.value.status}</div>
<div>${value.initphase.value.eta}</div>
</c:if>

<c:if test="${value.legalphase.exists}">
<div>${value.legalphase.value.status}</div>
<div>${value.legalphase.value.eta}</div>
</c:if>

<c:if test="${value.auctionphase.exists}">
<div>${value.auctionphase.value.status}</div>
<div>${value.auctionphase.value.eta}</div>
</c:if>

<c:if test="${value.analysisphase.exists}">
<div>${value.analysisphase.value.status}</div>
<div>${value.analysisphase.value.eta}</div>
</c:if>

Too much repetition, right?

My plan is to build a collection (a list actually) of value.prepphase, value.initphase, value.legalphase, value.auctionphase, value.analysisphase objetcs, and then:

<c:forEach var="phase" items="${now how to build the list?!?!?!}">
<c:if test="${phase.exists}">
<div>${phase.value.status}</div>
<div>${phase.value.eta}</div>
</c:if>
</c:forEach>

My problem is: how to build the list?

I've tried:

${java.util.Arrays.asList(value.prepphase, value.initphase, value.legalphase, value.auctionphase, value.analysisphase)} but value is not available;

[${value.prepphase}, ${value.initphase}, ${value.legalphase}, ${value.auctionphase}, ${value.analysisphase}] but this yields a list of 5 Strings ("[${value.prepphase}", "${value.initphase}" ... "${value.analysisphase}]")

I don't know what else to try.

UPDATE

Project's web.xml says <web-app version="3.0">.

rslemos
  • 2,454
  • 22
  • 32
  • Answer depends on EL version used. With EL 3.0 and up it's easy (just use "collection syntax", see documentaiton), else it's a little more convoluted. – BalusC Mar 23 '20 at 19:09
  • how do I know which EL version I'm using? – rslemos Mar 23 '20 at 19:11
  • Project's web.xml says `` – rslemos Mar 23 '20 at 19:14
  • In [another answer](https://stackoverflow.com/a/7237216/1535706) I've learned that "Servlet 3.0 comes with JSP/EL 2.2". So, isn't it EL 2.2? – rslemos Mar 23 '20 at 19:15
  • You're right if the target server is Servlet 3.0. Try upgrading the server. Else if the target server is actually newer, then just update web.xml version. – BalusC Mar 23 '20 at 19:17
  • Upgrading is not an option; unfortunately I must keep with what I have and work on it. – rslemos Mar 23 '20 at 19:18

1 Answers1

0

Found it:

<c:forEach var="phase" items="${[value.prepphase, value.initphase, value.legalphase, value.auctionphase, value.analysisphase]}">
...
</c:forEach>
rslemos
  • 2,454
  • 22
  • 32