How can I give EL expressions as parameters in nested jsp 2.0 tags?

I want to do something like this to call the JSP 2.0 tag:

<mytags:foo abc="<%=def%>">
  <mytags:bar ghi="<%=jkl%>"/>
</mytags:foo>

Where are the lines defand are jkldefined in the jsp earielr file. Suppose my tag files look like this:

foo.tag:

<%@ tag body-content="scriptless" %>
<%@ attribute name="abc" required="true" %>
<div class="${abc}">
  <jsp:doBody/>
</div>

bar.tag:

<%@ tag body-content="scriptless" %>
<%@ attribute name="ghi" required="true" %>
<div>${ghi}</div>

I want the result to look like this:

<div class="def">
<div>jkl</div>
</div>

(assuming that the variables defand jklare initialized, respectively, defand jklin the calling JSP file.)

The outer tag gets its attribute just fine ( <div class="def">), but the inner one doesn't work.

Is it possible? I get errors that cannot be resolved by jkl.

+3
source share
1 answer

body-content="scriptless" . , , , ( <% %>). EL.

, JSP, :

  <c:set var="def" value="def"></c:set>
  <c:set var="jkl" value="jkl"></c:set>

  <mytags:foo abc="${def}">
      <mytags:bar ghi="${jkl}"/>
  </mytags:foo>

, <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

+4

Source: https://habr.com/ru/post/1702999/


All Articles