Site Contents
Home
My Blog
ColdFusion
JRun
Flex
Wireless & Networking
Hardware & Gadgets
HDTV
Software Picks
Pictures
Contact Me
Search


My Articles & Papers
Flex Performance
Server/Client
mm.com Under the Hood
Multiple Instances of CFMX
Multiple Instance Config
NLB with ColdFusion
Clustering CFMX for J2EE
Multi-Tier Hardware LB w CFMX
Cisco CSS & Coldfusion MX
JRun 4 Jini based Clustering
WiFi Growth

2ID Tacweb

Other Hobbys
Body-For-Life Challenge

Personal Projects
Family Pool
Deck Gate

username:
password:
 

 
Building burcell.org

Welcome to bpurcell.org, the personal homepage of Brandon Purcell. I started building bpurcell.org many, many years ago to share information I ran across everyday in my role as a Support Engineer and Consultant for Macromedia/Adobe. As a support engineer and consultant I always had a lot to blog about but as I moved into managment roles at Adobe my technical content dwindled.

I currently work as the Director of Technology for Universal Mind. My primary responsiblity is managing the SpatialKey project and it has been an amazing experience. I have been spending a lot of time working with Amazon Ec2 and will share my experiences through the blog in the future. I truly believe that Cloud Computing is the IT platform of the future and we have built the SpatialKey architecture on top of Ec2.

Viewing Individual Entry / Main
January 26, 2005

The validators that are provided in Flex cannot be localized or have the error strings easily changed because they cannot have an id, which means they cannot be accessed from script and you cant bind objects that dont have an id. One solution is to subclass the various validators and override their error string properties so they access variables in the application. Then all you have to do is load in strings into those variables and youre all set.

In the example, if you type xyz and hit tab, you will see the validator kick in with the custom message from the app, that calls the invalidCharError() and in the AS file you will see that it returns the string defined in the MXML file. You can also type in a custom error in the second TextInput and change the error on the fly allowing you to localize the errors easily from an XML file or other source. Also try typing in 123 and hitting tab on the first input and you will see another customized error message. Just locate the different methods in the MXML AS API and override each of the methods you need custom errors for.Note that the validation logic itself doesnt change at all you are just overriding the error messages.

Thanks to Alex for providing a starting point for this example. You can download the code here and it is also shown below

MXML file:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml" >
<mx:Script>
 var invalidCharError:String = 
 "Default Error for Invalid Phone Number!!";
 var wrongLengthError:String = 
 "Hey dummy the phone number needs to be at least 10 digits long!!";
</mx:Script>
   
   <mx:Model id="myModel">
     <employee>
   <phoneNumber>{phone.text}</phoneNumber>
  </employee>
   </mx:Model>
   
   <MyPhoneNumberValidator xmlns="*" 
      field="myModel.employee.phoneNumber" />
 
 <mx:Label text="Phone Number"/>
 <mx:TextInput id="phone" />
 <mx:Label text="Custom Error Message"/>
 <mx:TextInput id="newError"/>
 
 <mx:Button click="invalidCharError = newError.text" 
 label="Change Error Message" />
</mx:Application>

Subclassed Validator (MyPhoneNumberValidator.as):

//
// Simple age validator.  
//   Verifies: AS components
//
class MyPhoneNumberValidator extends mx.validators.PhoneNumberValidator
{
 // The default is "Invalid characters in your phone number."
 public function get invalidCharError():String
 {
  return mx.core.Application.application.invalidCharError;
 }
 
 // The default is "Your telephone number must be at least 10 digits in length."
 public function get wrongLengthError():String
 {
  return mx.core.Application.application.wrongLengthError;
 }
 
}

Comments

After I posted this I realized that Matt Chotin had an answer for this as well. http://www.markme.com/mchotin/archives/006848.cfm


This post is throwing errors on your RSS feed. I tend to browse your blog through an Aggregator so I'd realy appreciate if you could fix this line:-

Then all you have to do is load in strings into those variables and you're all set.

You need to fix the apostraphe in you're.

Thanks.

Simon Baynes


 

Calendar
SunMonTueWedThuFriSat
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31            

Subject Archives
Amazon EC2 (15)
ColdFusionMX (155)
Corvette (3)
Flash Lite (4)
Flash Media Server (5)
Flash Player (3)
Flex (39)
General Web Dev (14)
HDTV (3)
Jboss (1)
Jquery (2)
JRun (59)
Max 2003 (3)
Other (33)
PC Hardware (16)
Software (17)
SpatialKey (7)
Wireless (8)
Working Out (1)

Search
RSS Feed
Feed Listing

www.flickr.com
Corvette - October 2005 brandonpurcell's Corvette - October 2005 photoset
Macromedia ColdFusion MX

Featured Links
Stock Footage
Page Render Time:203 user:""