0

I have a legacy Struts 1 application which uses the nested tag. Can I inject a dynamic parameter into the nested tag? For example,

<nested:select disabled="<c:out value='${requestScope.disableSelectBox}' />" />

I also tried doing:

<nested:select disabled="${requestScope.disableSelectBox}" />

In both of the above examples, the disabled attribute was not properly set and it was ignored. If I printout the value with a c:out, the correct value of disableSelectBox is displayed:

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

A colleague suggested that I should use:

<nested:select disabled="<%=request.getAttribute("disableSelectBox"); %>" />

The trouble is that it is considered bad practice to use java scriplets in a JSP page. Is there any way to embed a dynamic variable into a Struts 1 nested tag? Switching to Struts 2 is not an option.

Thanks!

4

1 回答 1

1

Struts 1(据我所知)不能让你这样做:

<nested:select disabled="<c:out value='${requestScope.disableSelectBox}' />" />

由于它无法处理其任何属性声明中的 JSP 标记,请检查所需nested:select disabled的属性。

但是 Struts 确实支持 EL 和 JSP Scriplets(所以你的同事是对的)。JSP Scriptlet 将“呈现” 的值<%=request.getAttribute("disableSelectBox"); %>并将其分配给<nested:select disabled="<%=request.getAttribute("disableSelectBox"); %>" />

所以(如果我假设这些值返回真或假,

<nested:select disabled="${requestScope.disableSelectBox}" />

<nested:select disabled="<%=request.getAttribute("disableSelectBox"); %>" />

将呈现为(如果结果返回 true)

<nested:select disabled="true" />

在它被发送到 Struts 渲染嵌套标签之前(抱歉使用“渲染”这个词,如果需要,可以使用 translate)。

于 2010-09-29T20:49:28.360 回答