一张是类别信息表,另外一张是基本信息表,在基本信息添加时,类别是一个下拉框进行选择,并把类别ID存储在基本信息表中;现在我要显示基本信息List,其中一列显示类别名称,我想请教下,我该如何取得类别名称,并显示在list中,下面是我的处理代码,名称取出来了,但是页面显示没出来,请高手指点,谢谢!
下面是list的显示页面,<s:property value='newInsuranceType.name'/>这行代码没获取到值<s:iterator value="newInsuranceList" id="newInsuranceList" status="index">
<tr>
<td align="center"><%=n++ %></td>
<td align="center">
<a href="infoNewInsurance.action?newInsurance.insuranceInformationId=<s:property value='#newInsuranceList.insuranceInformationId'/>" style="cursor:pointer;" target="_blank">
<s:property value="#newInsuranceList.name"/>
</a>
</td>
<td align="center">
<s:property value='newInsuranceType.name'/>&nbsp;
</td>
<td align="center">
<s:property value='#newInsuranceList.feeRate'/>&nbsp;</td>
<td align="center">
<s:property value='#newInsuranceList.procedureRate'/>&nbsp;</td>
<td align="center">
<s:property value='#newInsuranceList.directorDiscountRate'/>&nbsp;</td>
<td align="center">
<s:property value='#newInsuranceList.managerDiscountRate'/>&nbsp;td>
</tr>
</s:iterator>下面是action的处理方法,typeId获取到值了,newInsuranceType.getName()也有值,但是这里因为取的一条记录,所以返回值是typeBean里面public String list(){
try{
    newInsuranceList = newInsuranceService.findAllByFlag();
    int typeId = 0;
    if(newInsuranceList.size() > 0 && newInsuranceList != null){
       for(int i = 0; i<newInsuranceList.size(); i++){
       typeId = newInsuranceList.get(i).getTypeId();
       System.out.println("// Debug typeId = " + typeId);
       if(typeId > 0){
         newInsuranceType = newInsuranceTypeService.findById(typeId);
System.out.println("// Debug name = " + newInsuranceType.getName());
       }
     }
   }
   return "list";
}catch (Exception e) {
log.error(e.getMessage(), e);
return ERROR;
}
}请问我改如何解决这个问题,谢谢

解决方案 »

  1.   

     你这里的做法就有问题,你是要在页面显示newInsuranceList 这个集合内的信息,而这个集合内每一个对象都应该对应一个newInsuranceType.name;而你现在的做法是永远取出list最后一个对象的newInsuranceType.name;  
     你应该把所有的newInsuranceType取出来,然后在页面用struts2的表达式做一个比较.
      

  2.   

    你在action中加一个属性 name
    private String name ;
    //getter 和 setterpublic String list(){
    try{
        newInsuranceList = newInsuranceService.findAllByFlag();
        int typeId = 0;
        if(newInsuranceList.size() > 0 && newInsuranceList != null){
           for(int i = 0; i<newInsuranceList.size(); i++){
           typeId = newInsuranceList.get(i).getTypeId();
           System.out.println("// Debug typeId = " + typeId);
           if(typeId > 0){
             newInsuranceType = newInsuranceTypeService.findById(typeId);
             if (newInsuranceType != null){
                name = newInsuranceType.getName() ;
             }else{
                name = "NULL" ;         
             }    System.out.println("// Debug name = " + newInsuranceType.getName());
           }
         }
       }            
       return "list";
    }catch (Exception e) {
    log.error(e.getMessage(), e);
    return ERROR;
    }
    }
    <s:iterator value="newInsuranceList" id="newInsuranceList" status="index">
    <tr>
    <td align="center"><%=n++ %></td>
    <td align="center">
    <a href="infoNewInsurance.action?newInsurance.insuranceInformationId=<s:property value='#newInsuranceList.insuranceInformationId'/>" style="cursor:pointer;" target="_blank">
    <s:property value="#newInsuranceList.name"/>
    </a>
    </td>
    <td align="center">
    <s:property value='name'/>&nbsp;
    </td>
    <td align="center">
    <s:property value='#newInsuranceList.feeRate'/>&nbsp;</td>
    <td align="center">
    <s:property value='#newInsuranceList.procedureRate'/>&nbsp;</td>
    <td align="center">
    <s:property value='#newInsuranceList.directorDiscountRate'/>&nbsp;</td>
    <td align="center">
    <s:property value='#newInsuranceList.managerDiscountRate'/>&nbsp;td>
    </tr>
    </s:iterator>
      

  3.   

    这里name不能赋值为typeName,因为这里的name是基本信息表的一个属性,我现在加了一张视图,把东西取出来
      

  4.   

    一般最好别用视图,可以在 action 中重新拼个 List 再在页面中显示出来。
      

  5.   

    先把基本表的信息循环取出来,将每条数据对应的  类型名得到,将这些数据重新放到一个 List 在页面中显示新的List 的值。 这只是思路
      

  6.   

    把基本信息循环取出,并得到相应的 类型名称 ,将他们放到一个新的 List 中,在页面将新的 List 集合显示出来就行了,这只是思路,希望能帮到LZ