`
iliuyong
  • 浏览: 141508 次
  • 性别: Icon_minigender_1
  • 来自: 济南
社区版块
存档分类
最新评论

simple框架中在 propEditor 中使用checkbox 小总结

阅读更多

simple框架推荐:http://www.simpleframework.net/index.html

 

 

simple框架中在 propEditor 中使用checkbox 小总结

1.第一种写法
<field label="逻辑型?">
    <component name="temp"  type="checkbox" ></component>
</field>

此时生成的html是
<input type="checkbox" id="temp" name="temp" />

提交到服务器是 根据参数 temp取值
(1)选择时,服务器值为"on"
(2)不选是,客户端不提交这个字段,所以服务器端没有temp这个变量


2.第二种写法
<field label="逻辑型?">
    <component name="temp"  type="checkbox" >
        <defaultValue>true</defaultValue>
    </component>
</field>

此时生成的html是
<input type="checkbox" id="temp" name="temp" value="true" />

提交到服务器是 根据参数 temp取值
(1)选择时,服务器值为 "true"
(2)不选是,客户端不提交这个字段,所以服务器端没有temp这个变量

由此可见 checkbox 没有value属性的时候选中后提交默认值是"on",有value的时候选择后提交的是value指定的值。



3.用第二中写法是服务器端
可以用simple的工具将String转成Boolean很方便
ConvertUtils.toBoolean(compParameter.getRequestParameter("temp"), false)

4.疑问是:我下面2个语句
dataBinding.put("temp", true);
dataBinding.put("temp", false);
产生的客户端代码是相同的
<input type="checkbox" id="temp" name="temp" value="true" />
但表现不一样,一个被选中,一个没被选中
是否选择是通过脚本实现的吗?

 

大耳朵:

checkbox 是通过属性checked体现的,value仅仅是当checked提交到后台的值
所以,dataBinding.put("temp", true); 是js实现的

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics