我想在List中保存FormBean值,希望将它保存在Session中,并再次希望使用<logic:iterate>
在JSP上迭代不同FormBean值的列表。
我能够迭代列表或FormBean值<logic:iterate>
,但无法将它们组合在一起。
我试过这个例子。
<table width="75%" border="0" cellspacing="1" cellpadding="0">
<logic:iterate id="myId" name="sessionData" property="getInsuredPhoneList">
<tr>
<td width="25%"> <bean:write name="myId"/> </td>
</tr>
</logic:iterate>
</table>`
用于显示JSP的动作类:
List<String> getInsuredPhoneList = new ArrayList<String>();
getInsuredPhoneList.add("");
getInsuredPhoneList.add("");
getInsuredPhoneList.add("");
getInsuredPhoneList.add("");
getInsuredPhoneList.add("");
sessionData.setGetInsuredPhoneList(getInsuredPhoneList);
处理JSP的动作类:
InsuredPhoneFormBean partyForm1=(InsuredPhoneFormBean)actionForm;
String type=partyForm1.getPhoneTypeCode();
String area=partyForm1.getAreaCode();
String landlineNumber=partyForm1.getLandlineNumber();
String mobileNumber=partyForm1.getMobileNumber();
String email=partyForm1.getEmailAddress();
SessionData sessionData=getSessionData(request);
List<String> getInsuredPhoneList = new ArrayList<String>();
getInsuredPhoneList.add(type);
getInsuredPhoneList.add(area);
getInsuredPhoneList.add(landlineNumber);
getInsuredPhoneList.add(mobileNumber);
getInsuredPhoneList.add(email);
sessionData.setGetInsuredPhoneList(getInsuredPhoneList);
我的输出是:
住宅9988009988 abc@gmail.com
我想在这里getInsuredPhoneList
会保存多个FormBean值实例(Residential 9988009988 abc@gmail.com
,Office 9970009988 xyz@yahoo.com
),我希望通过getInsuredPhoneList
进行迭代,
这样
<table>
<logic:iterate id="myId" name="sessionData" property="getInsuredPhoneList">
<tr>
<td width="25%"> <bean:write name="myId" property="abc"/> </td>
</tr>
<tr>
<td width="25%"> <bean:write name="myId" property="xyz"/> </td>
</tr>
<tr>
<td width="25%"> <bean:write name="myId" property="pqr"/> </td>
</tr>
</logic:iterate>
</table>
(property =“pqr”表示FormBean的一个属性)
和输出像:
Residential 9988009988 abc@gmail.com
Office 9970009988 xyz@yahoo.com
答案 0 :(得分:0)
你的代码太乱了,以至于我无法真正理解和理解你的要求。但这是一般概念:
1)填充对象并将它们添加到动作类中的List(假设您有一个具有3个属性的对象Contacts
- office,tel,mail)
//in Action class
Contacts myContact = new Contacts();
myContact.setOffice("office1");
myContact.setTel("123454");
myContact.setMail("xx@xx.com");
List<Contacts> myList = new ArrayList<Contacts>();
myList.add(myContact);
//You can add more Objects to List here
2)在request
中设置列表对象,以便稍后在JSP中访问它
request.setAttribute("PHONE_LIST",myList);
3)在JSP中,你必须从request
获取List并迭代它以显示结果
//in JSP
<table>
<logic: iterate id="dataObject" name="myForm" property="PHONE_LIST">
<tr>
<td><bean: write name="dataObject" property="office" /></td>
<td><bean: write name="dataObject" property="tel" /></td>
<td><bean: write name="dataObject" property="mail" /></td>
</tr>
</logic: iterate>
</table>
希望这有帮助