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)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 香河县| 莫力| 察哈| 宁化县| 海安县| 合阳县| 保康县| 荣成市| 鹤山市| 楚雄市| 泽州县| 界首市| 永福县| 新田县| 陆良县| 伊通| 永胜县| 施秉县| 广东省| 孟津县| 周宁县| 武清区| 蓬溪县| 田林县| 铜鼓县| 太原市| 临潭县| 大关县| 东港市| 丰台区| 鄂州市| 且末县| 安丘市| 通海县| 论坛| 苏尼特左旗| 南安市| 灵宝市| 新田县| 松桃| 衡水市|