JaiswalTraining

Get the online training        


Get Best Tutorial on all major programing language


Corejava Servlet Jsp  Php  Hibernate  Ajax Web Service   Ejb2.1 Ejb3.0 Struts Struts2  JPA Spring Ibatis   JSF    JSF2.0  CoreJavaDesignPattern    Jquery  Flex J2EE-Design-Patterns  Jboss7  Maven  Contact Me                                                                                                                                                                        
            IGNOU SMU PTU Project                                           Training                                                                                                                              
              

Contact Us  0091- 9210721663         jaiswaltraining@gmail.com




Corejava
Servlet
Jsp
Php
Hibernate
Ajax
Web Service
Ejb2.1
Ejb3.0
Struts  
Struts2
JPA
Spring
Ibatis
JSF
JSF2.0
CoreJavaDesignPattern
Jquery
Flex
J2EE-Design-Patterns
Jboss7
Maven







Formatting data

Overview

Formatters
  • Formatters are a class of objects which take raw data and transform it into a presentable
    visual format.
  • Formatters can be configured to function in two modes
    • Real-time—Formatting is conducted on the fly automatically via data binding.
    • Scripted—Using ActionScript you can create instances of formatters explicitly
      when needed and process the data accordingly.
  • It is easy to use.
Built-in formatters
  • Flex provides a number of built-in formatters.
Formatter
  • Formatter is a parent object, and serves as a template for its family of more specialize
    formatters.
  •  As a base class, its utility is limited
The key function of all formatters
  • format
    • Takes in an object that needs to be formatted and returns a String with the result
The key property of all formatters
  • error
    • Use this property when trying to isolate a format problem.
    • An error has occurred when the format() function returns an empty String. 
NumberFormatter
  • Its the most popular formatter is NumberFormatter
  •  It handles numerical presentation details, such as decimal point precision
    and designating the character to use for thousands separation.
Properties of NumberFormatter.



Error messages of NumberFormatter



These error messages appear in the error property of NumberFormatter, which in this
case would be fmtNumber.error.

Example:-
  • Define a raw  data
  • Define a NumberFormatter
  • Format the raw data.

<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" 
        backgroundColor="white">
  <mx:XML id="myquant">
    <root>
      <quantity>
        <item name="Quantity" value="68.68954/>  
      </quantity>
    </root>
  </mx:XML>
  <mx:NumberFormatter id="fmtNumber" precision="2"/>  
  <mx:Label 
    text="Quantity {fmtNumber.format(myquant.quantity.item.@value)}lbs"/>
</mx:Application>                            

Output:-
  • The number 68.68954 was trunncated to 68.68


Download code

CurrencyFormatter
  • CurrencyFormatter supports all the same properties as the  NumberFormatter.
  • It includes two additional currency-specific attributes



Example:-

currencyformattest.mxml
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
  <mx:XML id="myincome">
    <root>
        <income name="income" sal="15000" />
      
    </root>
  </mx:XML>
  <mx:CurrencyFormatter id="fmtCurrency" precision="2"/>
  <mx:Label text="My Income in Dollar 
        {fmtCurrency.format(myincome.income.@sal)}"/>
</mx:Application>  

Output:-
  • CurrencyFormatter automatically adds the currency symbol.

Download code

DateFormatter
  • DateFormatter is probably the most heavily used of all formatters
  • It provides control over how dates appears in your output.
  • DateFormatter can format strings with dates and date objects
  • Additional date-specific attributes


Error messages of DateFormatter



Example:-

formatdatetest.mxml
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
  <mx:Script>
    <![CDATA[
      
      public var mydate:String = "11/15/11 17:42";
    ]]>
  </mx:Script>
  
  <mx:DateFormatter id="fmtDate" formatString="MM.DD.YY"/>
  <mx:Label text="Formatted Date: {fmtDate.format(mydate)}" />
  
</mx:Application>  

Output



Download code

PhoneFormatter

  • PhoneFormatter is particularly useful if you’re storing phone numbers
  • It is very similar to DateFormatter in that you have a formatString to specify the
    display pattern  to apply to the number
  • Its format() function accepts two types of objects: a String and a Number.

Properties of PhoneFormatter



Error messages of the PhoneFormatter



Example:-

<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
  <mx:XML id="myData">
    <root>
      <contactlist>
        <item name="contact" phone="2016679872" />
      </contactlist>
    </root>
  </mx:XML>
  <mx:PhoneFormatter id="fmtNumber" formatString="(###) ###-####"/>
  <mx:Label text="Contact Phone: {fmtNumber.format(myData.contactlist.item.@phone)}"/>
</mx:Application>  


Output:-



Download code


Real-time formatting

<mx:PhoneFormatter id="fmtPhone" formatString="###-###-####"/>
<mx:Label text="Contact Phone: {fmtNumber.format(“1112223333”)}"/>

Scripted formatting

  • You call it scripted, or dynamic formatting, this approach involves using
    ActionScript to process input on a more granular level.