</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;