2013-11-15 141 views
0

我想迭代一個具有另一個類作爲成員變量的類。下面是從類中的一些代碼:Struts邏輯:迭代列表的列表

public class UnregisteredCaseRecipient extends Auditable { 

private String peoplePin; 
private String recipName; 
private String roleCd; 
private String secLvl; 
private List<UnregisteredCaseRecipientNotification> unregisteredCaseRecipientNotifications; 

,我已經試過的JSP代碼如下:

     <logic:iterate name="caseRecip" id="unregisteredCaseRecipientNotifications"> 
           <td style="width: 25px;"> 
            <input type="checkbox" name="docRecipNotify" id="docRecipNotify" value="${unregisteredCaseRecipientNotifications.id}" ${unregisteredCaseRecipientNotifications.notificationCheck}/> 
           </td> 
         </logic:iterate> 

我已經試過類似this沒有運氣的東西。

<nested:iterate id="unregisteredRecipients" name="crFilingServiceListForm" property="unregisteredCaseRecipients" > 
            <nested:iterate id="unregisteredCaseRecipientNotifications" name="unregisteredRecipients"> 
             <td style="width: 25px;">notify: ${unregisteredCaseRecipientNotifications.notify} id: ${unregisteredCaseRecipientNotifications.id} 
              <input type="checkbox" name="docRecipNotify" id="docRecipNotify" value="${unregisteredCaseRecipientNotifications.id}" ${unregisteredCaseRecipientNotifications.notificationCheck}/> 
             </td> 
            </nested:iterate> 
           </nested:iterate> 

而且我也試過類似this的東西,沒有運氣。

     <logic:iterate name="crFilingServiceListForm" property="${caseRecip.unregisteredCaseRecipientNotifications" id="caseRecipNotify" indexId="j"> 
           <td style="width: 25px;"> 
            <input type="checkbox" name="docRecipNotify" id="docRecipNotify" value="${caseRecipNotify.id}" ${caseRecipNotify.notificationCheck}/> 
           </td> 
         </logic:iterate> 

感謝,

湯姆

+0

你得到的錯誤是什麼? –

+0

選項1獲取以下錯誤:「javax.servlet.jsp.JspException:無法爲此集合創建迭代器」選項2沒有錯誤,但字段爲空。選項3獲得500錯誤,並顯示以下消息:「OracleJSP:發生錯誤。請向您的應用程序/系統管理員尋求支持。程序員應考慮將init-param debug_mode設置爲」true「以查看完整的異常消息。爲幫助 –

回答

2

我能夠用嵌套的,而不是得到這個工作:

<c:forEach items="${crFilingServiceListForm.unregisteredCaseRecipients}" var="unregisteredRecip"> 
    <c:forEach items="${unregisteredRecip.unregisteredCaseRecipientNotifications}" var="unregisteredNotification"> 
    <td style="width: 25px;"> 
     <input type="checkbox" name="docRecipNotify" id="docRecipNotify" value="${unregisteredNotification.id}" ${unregisteredNotification.notificationCheck}/> 
    </td> 
    </c:forEach> 
    </tr> 
</c:forEach> 

感謝您的幫助大家!

Tom

0

試試這個:

<logic:iterate name="unregisteredCaseRecipientList" id="unregisteredCaseRecipient"> 
    <logic:iterate name="unregisteredCaseRecipient" property="unregisteredCaseRecipientNotifications" id="unregisteredCaseRecipientNotification"> 
     <td style="width: 25px;"> 
      <input type="checkbox" name="docRecipNotify" id="docRecipNotify" value="${unregisteredCaseRecipientNotification.id}" ${unregisteredCaseRecipientNotification.notificationCheck}/> 
     </td> 
    </logic:iterate> 
</logic:iterate> 

否則,你可以使用<bean:write/>而不是$ {}

祝您好運!

+0

感謝@ CPU100當我嘗試這個,我得到「500內部服務器錯誤 javax.servlet.jsp.JspException:找不到豆unregisteredCaseRecipientList在任何範圍內 \t在org.apache.struts.taglib.TagUtils.lookup( TagUtils.java:992) \t at org.apache.struts.taglib.logic.IterateTag.doStartTag(IterateTag.java:234)「謝謝@jvazquez –

+0

你必須把它放到一個範圍內,比如請求。例如request.setAttribute(「unregisteredCaseRecipientList」,myList); – jvazquez