Greetings, here is the problem. I have a page called entList.jsp, that works with a collection:
<c:forEach var = "pack" items = "${packingList}">
<!--Here goes something with outputting the pack instance in a required format-->
</c:forEach>
Everything works great, and the parameter packingList is passed as an attribute of the request by the action handler that calls this page. Actually packingList is of type Collection<GenericBean>.
It turned out that this page (the fragment it stores) is actually pretty useful, and can be used in many places with different collections. So I tried to include this page like this (in another page):
<jsp:include page="entList.jsp">
<!-- Pass the required collection as a parameter-->
<jsp:param name = "packingList" value = "${traffic.packingList}"/>
</jsp:include>
However, now this fragment does not see the argument packingList. I tried to rewrite the fragment like this (since now it’s a parameter):
<c:forEach var = "pack" items = "${param.packingList}">
<!--Here goes something with outputting the pack instance in a required format-->
</c:forEach>
But now it generates an exception, since it treats packingList as a string and not a collection. So right now the solution is like this – set the required collection as an attribute in the action handler code:
// This is the original instance set by the action
request.setAttribute("traffic", traffic);
// And this is the additional one, to be used by entList.jsp
request.setAttribute("packingList", traffic.getPackingList());
So the question is – can jsp:param tag receive a collection as it’s value? I read the documentation for the JSP tags and it remains unclear – it seems like the only thing you can pass in such a way it’s string parameters (or something that can be converted to string), but no complicated objects.
you should be using a tag file, and declare the tag with the correct parameter types.
e.g. as
packingList.tagThen, place this file in
WEB-INF/tagsthen, add to your jsp file
see http://download.oracle.com/javaee/1.4/tutorial/doc/JSPTags5.html for more info