1

我想将 FormBean 值保存在 List 中,想将其保存在 Session 中,并再次想通过 JSP 使用<logic:iterate>. 我能够迭代列表或 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.comOffice 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

4

1 回答 1

0

你的代码太乱了,我无法真正理解和理解你在问什么。但这是一般概念:

1)填充对象并将它们添加到操作类中的列表(假设您有一个Contacts具有 3 个属性的对象 - 办公室、电话、邮件)

//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 中,您必须从中获取 Listrequest并对其进行迭代以显示结果

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

希望这可以帮助

于 2012-10-17T06:14:40.183 回答