6
votes

I have the following code:

<bean:define id="hasDocuments" name="BudgetSimulationDetailForm" property="hasDocuments" type="java.lang.Boolean"/> 
<%
    request.setAttribute("enablebtnRelatedDocs", "true"); 
    request.setAttribute("hasDocuments", String.valueOf(hasDocuments));
%>

I want to remove the scriptlet, I tried using c:set with different scopes but it didn't work. Is it possible to set a request attribute using JSTL tags?

I tried this and did not work:

<c:set name="enablebtnRelatedDocs" value="true" scope="request"/>

and also

<c:set name="enablebtnRelatedDocs" value="${true}" scope="request"/>

Afterwards there is an include:

<jsp:include page="/gema/jsp/includes/detail/top_Detail.jsp">
    <jsp:param name="title_key" value="${title}" />
    <jsp:param name="title_bundle" value="buc" />           
    <jsp:param name="standard_buttons_include" value="true" />
    <jsp:param name="typeId" value="53555" />
    <jsp:param name="detail" value="budget" />
</jsp:include>

Inside the included JSP the request attribute is not visible, apparently.

2
c:set should work fine. Show us what you tried.Sotirios Delimanolis
And what does that do? Why do you think it doesn't work?Sotirios Delimanolis
Inside top_Detail.jsp there is a scriplet that reads request.getParameter and request.getAttribute and both return null.Lluis Martinez

2 Answers

11
votes

Sounds Good, You want to use JSP Standard Tag Library instead of Scriplet.

Yes, It's possible using c:set. Read more about Core Tag Library

<c:set var="enablebtnRelatedDocs" value="${true}" scope="request"/>

<c:out value="${requestScope.enablebtnRelatedDocs }"/>

By default c:set set a attribute in page context. you can set it in any scope.

3
votes

By default, the JSTL Core library function "set" accepts the following attributes:

JSTL Core set property (credits to tutorialspoint.com) : value, target, property, var, scope

You should use "var=" instead of "name=". Hope this helps!

Happy coding! 1: enter image description here