我有一个使用嵌套标签的旧版 Struts 1 应用程序。我可以将动态参数注入(inject)嵌套标签吗?例如,
<nested:select disabled="<c:out value='${requestScope.disableSelectBox}' />" />
我也尝试过这样做:
<nested:select disabled="${requestScope.disableSelectBox}" />
在上面的两个示例中,禁用属性未正确设置并且被忽略。如果我用 c:out 打印该值,则会显示 disableSelectBox 的正确值:
<c:out value="${requestScope.disableSelectBox}" />
一位同事建议我应该使用:
<nested:select disabled="<%=request.getAttribute("disableSelectBox"); %>" />
问题在于,在 JSP 页面中使用 java scriplet 被认为是不好的做法。有没有办法将动态变量嵌入到 Struts 1 嵌套标签中?切换到 Struts 2 不是一个选择。
谢谢!
最佳答案
Struts 1(据我记得)不允许你这样做:
<nested:select disabled="<c:out value='${requestScope.disableSelectBox}' />" />
由于它无法处理任何属性声明中的 JSP 标记,请检查什么 nested:select disabled
属性必需需求。
但是 Struts 确实支持 EL 和 JSP Scriplet(所以你的同事是正确的)。 JSP Scriptlet 将“呈现” <%=request.getAttribute("disableSelectBox"); %>
的值并将其分配给 <nested:select disabled="<%=request.getAttribute("disableSelectBox"); %>" />
所以(如果我假设这些值返回 true 或 false,
<nested:select disabled="${requestScope.disableSelectBox}" />
和
<nested:select disabled="<%=request.getAttribute("disableSelectBox"); %>" />
将被渲染为(如果结果返回true)
<nested:select disabled="true" />
在发送到 Struts 渲染嵌套标签之前(抱歉使用了“渲染”一词,如果需要,您可以使用翻译)。
关于java - 具有动态参数的 Struts 嵌套标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3825513/