一张是类别信息表,另外一张是基本信息表,在基本信息添加时,类别是一个下拉框进行选择,并把类别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.   

    这里可以用视图,但是视图一般最好别用,我遇到类似问题时会想到拼对象实现。 在action 中新创建一个List,把要显示的数据放到新的 List 中,再到页面中取出即可,我把你的代码改了下,你看看能不能帮上你的忙 ,如下:public String list(){
    try{
    //创建一个新的 List
    List  list = new ArrayList();
        newInsuranceList = newInsuranceService.findAllByFlag();
        int typeId = 0;
        if(newInsuranceList.size() > 0 && newInsuranceList != null){
           for(int i = 0; i<newInsuranceList.size(); i++){
         //创建一个 Map
           Map<String,Object> map = new HashMap<String,Object>();
           //用对象接收 (Object )
          
              typeId = newInsuranceList.get(i).getTypeId();
             //加入页面要显示的值,依次得到你想要输出的值
             map.put("feeRate",newInsuranceList.get(i).getFeeRate());  
             map.put("procedureRate",newInsuranceList.get(i).getProcedureRate());
                  map.put("directorDiscountRate",newInsuranceList.get(i).getDirectorDiscountRate());
             map.put("managerDiscountRate",newInsuranceList.get(i).getManagerDiscountRate());
           System.out.println("// Debug typeId = " + typeId);
           if(typeId > 0){
                 newInsuranceType = newInsuranceTypeService.findById(typeId);
                 System.out.println("// Debug name = " + newInsuranceType.getName());
                 map.put("name",newInsuranceType.getName());
           }
           list.add(map);
         }
       }            
       return "list";
    }catch (Exception e) {
    log.error(e.getMessage(), e);
    return ERROR;
    }
    }
         页面可以不用改了,还是那样取的,LZ试试吧,不行了再问我
      

  2.   

    在service中写一个加载List的方法,然后塞到页面就可以了