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