Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set request attribute using JSTL

Tags:

java

jsp

jstl

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.

like image 832
Lluis Martinez Avatar asked Jun 20 '14 14:06

Lluis Martinez


2 Answers

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.

like image 169
Braj Avatar answered Nov 16 '22 17:11

Braj


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

like image 24
Andrei Rusu Avatar answered Nov 16 '22 19:11

Andrei Rusu