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 眼鏡蛇 閱讀(105) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          <2025年6月>
          25262728293031
          1234567
          891011121314
          15161718192021
          22232425262728
          293012345

          導航

          統計

          常用鏈接

          留言簿(6)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 乌苏市| 双江| 东丰县| 灵台县| 新乡县| 浮山县| 滕州市| 丽江市| 泊头市| 北宁市| 徐汇区| 林甸县| 湘潭县| 中江县| 招远市| 广灵县| 巍山| 塔河县| 新巴尔虎右旗| 工布江达县| 铜川市| 金溪县| 沽源县| 惠东县| 通州区| 宜阳县| 尼勒克县| 黔西县| 吉安市| 敦煌市| 永吉县| 东阿县| 若羌县| 建德市| 冷水江市| 区。| 乳源| 长治县| 五台县| 高唐县| 新沂市|