2013-07-12 28 views
3

基本上,我的問題很簡單,但它需要知道Struts 1.1並且仍然存在的人。Struts 1.1嵌套<nested:equal>和<nested:write>組合

我嘗試的建立在僞代碼如下所示:

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文檔。

+0

你爲什麼使用嵌套,你對EL感到失望嗎? –

+0

完全不是,不幸的是我不允許在我目前正在維護的遺留系統中使用任何「尚未使用」的技術。 – JBA

+0

嗯,我再次檢查了項目文件。在每個JSP中有以下行: <%@ include file =「taglib.inc」%> 在相應文件中有tags-tiles,tags-html,tags-logic,tags-bean和tags-嵌套包括...我的權利,我現在可以使用EL? – JBA

回答

0

雖然羅馬C的解決方案的工作完美我也設法與嵌套的標籤一起得到它。

我遺憾的是不允許發佈的原始來源,然而,這是什麼呢&它是如何工作現在:

=>對不起,最壞的情況下在格式化PLZ,20分鐘後,我放棄了< =

<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> 
0

使用

<%@ 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>