Reputation: 140
I'm trying to create a tag file that in a way "extends" the <jsp:include>
tag. Basically I want to add custom logic so that in certain circumstances it will include a different file. I got it working fine for regular <jsp:include>
tags, but I'm still struggling when there are <jsp:param>
tags in the picture.
What I want to be able to do is this:
In the normal jsp code, main.jsp:
<custom:jsp-include page="include.jsp">
<jsp:param name="a" value="b"/>
<jsp:param name="x" value="y"/>
</custom:jsp-include>
And in the tag file, customInclude.tag:
...
<jsp:include page="${someJspFile}">
//SOMETHING-UNKNOWN-HERE
</jsp:include>
And the expected result is that the file in the variable someJspFile is called, with all the parameters defined in the main.jsp. Ie parameter a=b and x=y in this case.
But I don't know how to make this happen. I have tried using <jsp:doBody var="bodyContent"/>
, and then put ${bodyContent}
inside the <jsp:include>
, but that just results in an error. The error depends on the type of body-content I have defined for the tag file. If I set it to "tagdependent" then the error is:
Expecting "jsp:param" standard action with "name" and "value" attributes
...and if I set it to "scriptless", then the error is for the main.jsp code, with the error:
The jsp:param action must not be used outside the jsp:include, jsp:forward, or jsp:params elements
Surely there must be a way to achieve this? Or of a more more general point of view, there must be a way to pass along the body content as untouched, from one tag (my custom tag file in this case) to another (<jsp:include>
in this case), right?
Note that it's not specifically the possibility to put ${bodyContent}
inside the <jsp:include>
tag that I am after, since I can see how that could be considered as an eval type function if it would work, and it's not the possibility of doing eval that I am after. Maybe there is some special placeholder or similar, that I can put inside the <jsp:include>
tag, that will make it work just as if I had copy pasted the <jsp:param>
tags from main.jsp into the body of the <jsp:include>
in customInclude.tag?
Regards
/Jimi
Upvotes: 1
Views: 198