JSF学习日志2

各种数据类型的转换
<h:inputText value="#{payment.amount}">
<f:convertNumber minFractionDigits="2"/>
</h:inputText>

<h:inputText value="#{payment.date}">
<f:convertDateTime pattern="MM/yyyy"/>
</h:inputText>


<h:outputText value="#{payment.amount}">
<f:convertNumber type="currency"/>
</h:outputText>


The converter Attribute
An alternate syntax for attaching a converter to a component is to add the converter
attribute to the component tag. You specify the ID of the converter like this:
<h:outputText value="#{payment.date}" converter="javax.faces.DateTime"/>
This is equivalent to using f:convertDateTime with no attributes:
<h:outputText value="#{payment.date}">
<f:convertDateTime/>
</h:outputText>
A third way of specifying the converter would be as follows:
<h:outputText value="#{payment.date}">
<f:converter converterId="javax.faces.DateTime"/>
</h:outputText>
All JSF implementations must define a set of converters with predefined IDs:
• javax.faces.DateTime (used by f:convertDateTime)
• javax.faces.Number (used by f:convertNumber)
• javax.faces.Boolean, javax.faces.Byte, javax.faces.Character, javax.faces.Double,
javax.faces.Float, javax.faces.Integer, javax.faces.Long, javax.faces.Short (automatically
used for primitive types and their wrapper classes)
• javax.faces.BigDecimal, javax.faces.BigInteger (automatically used for
BigDecimal/BigInteger)



显示错误消息,有两种,一种是,把所有信息直接就显示在页面的最上面。还一种可以显示在当前位置,像这样
<h:inputText id="amount" label="#{msgs.amount}" value="#{payment.amount}"/>
<h:message for="amount"/>

验证,这个也可以结合上面的message使用
<h:inputText id="amount" value="#{payment.amount}">
<f:validateLongRange minimum="10" maximum="10000"/>
</h:inputText>
还有一种方法就是把这验证写在Bean里,像这样
public class PaymentBean implements Serializable {
     @Min(10) @Max(10000)
     private double amount;


眼镜蛇

posted on 2014-12-08 17:54 眼镜蛇 阅读(104) 评论(0)  编辑  收藏


只有注册用户登录后才能发表评论。


网站导航:
 
<2024年11月>
272829303112
3456789
10111213141516
17181920212223
24252627282930
1234567

导航

统计

常用链接

留言簿(6)

随笔分类

随笔档案

文章分类

文章档案

搜索

最新评论

阅读排行榜

评论排行榜