JSF 2.0 (2)

JSF数据类型转换技巧

The course English 217 definitely is a tough one. Eight books need to be read through this short summer. How can i finish it?


Continue to talk about JSF here:

Converter is very important when the data transfers from the front page to the back-end java beans. For those basic generic data type, such as String, boolean, int, JSF 2.0 provides the conversion automatically. But for Date type, we need to claim one tag <f:convertDateTime> inside the input tag.

Here is the first case, for boolean type:

<div class="controls">
	<h:selectOneRadio value="#{tmpBean.federalOs}">
	<f:selectItem itemValue="true" itemLabel="Yes" />
	<f:selectItem itemValue="false" itemLabel="No" />
	</h:selectOneRadio>
</div>
The point needs to be mentioned here is for boolean, only two values "true" or "false" are acceptable, other values such as "Y" or "N" can not be considered as proper boolean values. This kind of setting is reasonable since it follows the rules in Java AND won't mess up something. Therefore, in your application, if you want to set one parameter value (to you, it's boolean) to be "Y" or "N", you probably need to set it to be String type.


Another case if for Date type:

<h:inputText class="span2" value="#{tmpBean.letDate}">
	<f:convertDateTime pattern="MM/dd/yyyy"/>
</h:inputText>
The tag is very clear here.


The java beans for above two parameter are:

// Bean name: tmpBean
//...
private boolean federalOs;

//...
private Date letDate




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值