开发者

Struts Nested Tag with Dynamic Parameters

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!


Struts 1 (as far as I can remember) cannot allow you to do:

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

As it can't process JSP tags inside any of their attribute declarations, Check what nested:select disabled attribute required needs.

But Struts do support EL and JSP Scriplets (so your colleague is correct). JSP Scriptlet will "render" the value of the <%=request.getAttribute("disableSelectBox"); %> and assign it to the <nested:select disabled="<%=request.getAttribute("disableSelectBox"); %>" />

So (if I assume that the values returns a true or false,

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

and

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

will be rendered as (if results returns true)

<nested:select disabled="true" />

before it is sent to Struts to render the nested tag (sorry for using the word "render", you can use translate if you want).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜