【问题标题】:Using another bean's property in the value attribute of a logic:equal tag在 logic:equal 标记的 value 属性中使用另一个 bean 的属性
【发布时间】:2015-05-04 17:06:06
【问题描述】:

我想使用 Struts1 中的逻辑标记来比较两个独立 bean 的属性:

<logic:equal name="beanOne" property="beanOneProperty" 
    value="<bean:write name="beanTwo" property="beanTwoProperty" />">

  //code to execute

</logic:equal>

但是上面的代码导致如下错误信息:

无法找到标记属性 beanTwo 的标记属性信息。

如何将 value 属性分配为存储在第二个 bean 中的内容?

还有比这更简洁的解决方案吗?

<bean:define id="beanTwoProperty" scope="request">
    <bean:write name="beanTwo" property="propOne"/>  
</bean:define>

<logic:equal name="beanOne" property="beanOneProperty" value="<%=beanTwoProperty">


我的问题与this one 重复,但我很想看看是否有纯Struts-1 解决方案可用。

【问题讨论】:

  • 您可以使用 Struts 1 标签的 EL 版本,但是……当您不需要使用 Struts 标签时,不要使用。 EL 标签只是复制了你的容器提供的开箱即用的功能——它们是在 EL 无处不在之前编写的。

标签: struts-1


【解决方案1】:

您可以按照您的建议使用&lt;bean:define ... /&gt;

或者你可以使用 EL:

<logic:equals name="beanOne" property="beanOneProperty" value="${beanTwo.beanTwoProperty}">

或者你可以跳过&lt;bean:define ... /&gt;(假设是getter):

<logic:equals name="beanOne" property="beanOneProperty" value="<%= beanTwo.getBeanTwoProperty() %>">

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-12-08
    • 1970-01-01
    • 1970-01-01
    • 2017-10-14
    • 2012-12-24
    • 2017-08-28
    • 2015-10-23
    相关资源
    最近更新 更多