struts,动态显示页面的textbox

    当页面上显示的textbox 是不能确定个数的时候,要想显示和更新数据就似乎有些不可能,但是通过HashMap,却可以实现这一点
    在ActionForm中定义一个类型为HashMap的类变量
  private  HashMap investimatesubMap  =   new  HashMap();

    
public  Object getInvestimatesubMap(String key) ... {
        
return investimatesubMap.get(key);
    }

    
public   void  setInvestimatesubMap(String key, Object value) ... {
        
this.investimatesubMap.put(key, value);
    }


    
private  Collection listInvestimatesub;
   
    
public   void  resetListInvestimatesub()  {
        Collection myInvestimatesub 
= new ArrayList();
       
        Collection myKeys    
= investimatesubMap.keySet();
        
for (Iterator it = myKeys.iterator(); it.hasNext();) {
            String         key         
= (String) it.next();
            String         getKey        
= this.investimatesubMap.get(key).toString();
            String[]    properties    
= key.split("_");
            String         property    
= properties[0];
            String         vol            
= properties[1];
            String        id            
= properties[2];

                InvestimatesubForm investimatesubForm 
= new InvestimatesubForm();
                investimatesubForm.setEttprojid(
this.ettprojid);
                investimatesubForm.setVoltagegrade(vol);
                investimatesubForm.setInvestestimateid(id);

               
                investimatesubForm.setTranssubstninvest(getKey);
               
                myInvestimatesub.add(investimatesubForm);

        }

       
        
this.listInvestimatesub = myInvestimatesub;
    }



    
public  Collection getListInvestimatesub()  {
        
if (this.listInvestimatesub == null{
            resetListInvestimatesub();
        }

       
        
return listInvestimatesub;
    }


    
public   void  setListInvestimatesub(Collection listInvestimatesub)  {
        
this.listInvestimatesub = listInvestimatesub;
    }

注意:变量一定要实例化,get方法的返回值一定是Object,set方法的value类型也一定是Object。

    在进入jsp之前的Action中
       InvestimatemainForm investimatemainForm = new InvestimatemainForm() ;
          String key =
"lineinvest_" + vol + "_" + id
       investimatemainForm.setInvestimatesubMap( "key " " testValue " );

    jsp中
< html:text  property ="investimatesubMap( lineinvest_220_ 111)"  maxlength ="12"   style ="width: 100px;" />
map中的值一定不能加引号,错误示例:
< html:text  property ="investimatesubMap(‘lineinvest_220_111’)"  maxlength ="12"   style ="width: 100px;" />


可以用key值传递一些跟当前所填写的字段相关的信息,再在后台解析
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值