【问题标题】:Nested <nested:equal> and <nested:write> in combination嵌套 <nested:equal> 和 <nested:write> 组合
【发布时间】:2013-07-12 14:20:01
【问题描述】:

基本上,我的问题很简单,但它需要知道 Struts 1.1 并且还活着的人。

我尝试在伪代码中构建的内容如下所示:

IF element.method1 = true THEN
   IF element.method2 = true THEN
      COLOR.GREEN, PRINT element.prop1
   ELSE
      COLOR.RED, PRINT element.prop1
   END
ELSE
   COLOR.BLACK, PRINT element.prop1
END

整个事情都发生在一个迭代中。所以这里是目前有效但还不是目标:

<nested:equal property="method1" value="true">
    <nested:write property="prop1" /> 
</nested:equal>

<nested:notEqual property="method1" value="true">
    <nested:write property="prop1" />
</nested:notEqual>

现在真正让我抓狂的是,它也有效:

<nested:equal property="method1" value="true">
   <nested:equal property="method2" value="true">
   </nested:equal>                
</nested:equal>
                        
<nested:notEqual property="method1" value="true">
   <nested:write property="prop1" />
</nested:notEqual>

但是每当我在两个内部 nested:equal 标记之间插入一些东西时,它就不会编译。

所以我的最终解决方案(见下文)不会编译抱怨"Missing Endtag for nested:write."

<nested:equal property="method1" value="true">

   <nested:equal property="method2" value="true">
           <nested:write property="element.prop1" />
   </nested:equal>   
                        
</nested:equal>
                        
<nested:notEqual property="method1" value="true">
    <nested:write property="element.prop1" />
</nested:notEqual>

大约 4 小时后,我仍然不知道如何处理这个问题,所以任何建议都会非常感激,甚至在这篇文章发布 2 周后也会有所帮助,因为我的下一步是深入研究 Struts 1.1 文档。

【问题讨论】:

  • 你为什么用嵌套,你对EL失望吗?
  • 完全没有,不幸的是,我不允许在我当前维护的遗留系统中使用任何“尚未使用”的技术。
  • 好吧,我再次检查了项目文件。在每个 JSP 中都有以下行: 在相应的文件中包含 tags-tiles、tags-html、tags-logic、tags-bean 和 tags-nested。 . 我说得对吗?我现在可以使用 EL 了吗?
  • 用EL,很简单,不用写nested标签。您也可以使用 JSTL 代替 Struts1 标签,这是迁移到新版 Struts 的一大步。
  • 此外,Struts 1.3.10 通过 contrib 在其发行版中支持 EL 和 JSTL。

标签: java jsp struts nested equals


【解决方案1】:

虽然 Roman C 的解决方案完美运行,但我也设法将它与嵌套标签组合在一起。

很遗憾,我不允许发布原始来源,但这就是它现在的作用和工作方式:

<nested:form action="/someReq" styleClass="standard">
    <nested:present property="myBean.genList">

        <nested:iterate property="myBean.genList" indexId="index">

            <nested:equal property="method1" value="true">

                <nested:equal property="method2" value="true">
                    <strong class="green">
                        <nested:write property="prop1" />
                    </strong>
                </nested:equal>

                <nested:notEqual property="method2" value="true">
                    <strong class="red">
                        <nested:write property="prop1" />
                    </strong>
                </nested:notEqual>

            </nested:equal>

            <nested:notEqual property="method1" value="true">
                <nested:write property="prop1" />
            </nested:notEqual>

        </nested:iterate>

    </nested:present>
</nested:form>

【讨论】:

    【解决方案2】:

    使用

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

    代码看起来像

    <c:choose>
      <c:when test="${element.method1 == true}"> 
        <c:choose> 
          <c:when test="${element.method2 == true}"> 
            <span style="color:green;"><c:out value="${element.prop1}/></span>
          </c:when>
          <c:otherwise>
            <span style="color:red;"><c:out value="${element.prop1}/></span>
          </c:otherwise>
        </c:choose>
      </c:when>
      <c:otherwise>
        <span style="color:black;"><c:out value="${element.prop1}/></span>
      </c:otherwise>
    </c:choose>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-04-19
      • 1970-01-01
      • 2017-07-26
      • 2019-03-16
      • 2020-11-09
      • 2021-08-21
      • 2019-03-15
      相关资源
      最近更新 更多