首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

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

2012-08-26 
simple框架中在 propEditor 中使用checkbox 小总结simple框架推荐:http://www.simpleframework.net/index.

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实现的

热点排行