struts html:text标签 从页面返回到后台时如果这个值是Long类型的变量并且没有填值,传到后台会被赋值成默认值0。
不知道这个问题能不能解决。
例如:<html:text styleId="atmMaximumBurstSize" property="atmMaximumBurstSize"/>
如果改成<input type="text" id="atmSustainableCellRate" name="atmSustainableCellRate" value="<bean:write name="form" property="atmSustainableCellRate" />"/>还是存在这个问题。
是不是因为struts解析标签的时候把“Long”类型转换成原生类型“long”才出来的默认值?不知道有没有办法解决。

解决方案 »

  1.   

    Long类型的变量要么 是 数字, 不能为空的吧? 为空 则表示 0
      

  2.   

    你可以在action中得到这个值 进行你想到的操作
      

  3.   

    不会的,用request.getParamterValue(“atmMaximumBurstSize”);返回一个对象后,
    判断是不是null,如果是null的话,说明就是没填,你在进行你自己的处理了。
    也不知道你是不是这个目的
      

  4.   

    可能是我没说清楚。
    step1:这个值本来就是null的,传到页面用标签<html:text styleId="atmMaximumBurstSize" property="atmMaximumBurstSize"/>显示也是空的。step2:提交页面,从actionform中用getAtmMaximumBurstSize()获取这个值就变成“0”了。
    我不想要这个零,还想要null值。
    用request.getParamterValue(“atmMaximumBurstSize”);我还没试,但是我不想这么用,页面中这种值太多了,起码有几十个,每个都这么做太麻烦
    大家帮忙想想办法吧,这个问题困扰我好久了,网上找了好久也没找到办法。
      

  5.   

    你在step2中从actionform中用getAtmMaximumBurstSize()获取这个值,然后判断一下,如果为0的话,让他改成null不就可以了
    String atmMaximumBurstSize = getAtmMaximumBurstSize()== 0 ? "" : getAtmMaximumBurstSize()+ "";
      

  6.   

    <input type="text" id="atmSustainableCellRate" name="atmSustainableCellRate" value=" <bean:write name="form" property="atmSustainableCellRate" />"/>
    可以把这句话改成:
    <input type="text" id="atmSustainableCellRate" name="atmSustainableCellRate" value="atmSustainableCellRate==0?null:atmSustainableCellRate"/>
      

  7.   

    这样不行,因为有可能填的就是0,这样就不能把0改成null
      

  8.   

    你在action中对你输入的数据进行判断,如果输入为空的话,在数据库中不插入该字段,如果输入的值不能为负数的话插入一个-1什么的,当他读出时在对插入的值进行判断
    总之,对插入的sql进行动态的判断
      

  9.   

    若项目结合了spring的话 
    写拦截器 拦截你的这个参数 (在拦截方法(Convert_text_Null)里)对它做统一的处理。
    struts1版本则此法无效。
      

  10.   

    这是ActionForm对输入先进行了预处理了,如果输入的数据不能包装成Long型的话,它就会自动传一个0过来。比如你输入一个字母a的话也会变为0.所以你没有办法解决。
    但我不明白的是楼主为什么在formbean里面要用Long型的数据,你用一个String不就行了吗?在页面里面验证一下,再在formbean里面验证一下,action里面把String改成Long也不难啊。。
      

  11.   

    用El 表达式就可以了<input type="text" id="atmSustainableCellRate" name="atmSustainableCellRate" value=" <bean:write name="form" property="atmSustainableCellRate" />"/>改成
    <input type="text" id="atmSustainableCellRate" name="atmSustainableCellRate" value="${form.atmSustainableCellRate==0?"":form.atmSustainableCellRate}"/>
      

  12.   

    重写一下ActionForm的reset方法试试
      

  13.   

    用iframe吧,假设分成了两个,一个叫left,一个叫right,在left中用parent.right.xx="你的值"就可以传过去。
      

  14.   

    后台转换失败的话都会变成0。楼主可以在validata方法中判断参数。或者我记得Struts里好像有一个Convert机制。。忘了是不是了。。没用过。
      

  15.   

    好像用input 里面用bean:whrite可以解决这个默认值0的问题,但是我这个actionform是复杂类型的,里面套了一层javabean 也就是要用property="lanws.ipInterfaceIPAddress"这种格式,这样用input形式的控件就不能传值到后台。