RE: [flexcoders] What's the best way to bind ValueOject model data to a form and back again

2007-12-16 Thread Randy Martin
I've just posted a little demo on my blog, http://www.martinized.us/, that
should answer some of your questions. The data entry form contains a date
field that allows both selection from the date chooser and direct entry with
validation into the date field. There is also a fair amount of code that
demonstrates data binding to value objects, entry fields, and back-end
remote objects.

HTH,
Randy
 

-Original Message-
From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of Muzak
Sent: Friday, December 14, 2007 11:04 PM
To: flexcoders@yahoogroups.com
Subject: Re: [flexcoders] What's the best way to bind ValueOject model data
to a form and back again

Use a DateField component for displaying/editing Date type data, in
combination with a DateFormatter for displaying the right format in the
DateField textfield.

Not sure if the following will make sense, but here's something I've used:

// in a Script block
// currentNewsItem is a VO retrieved from the Model.
   [Bindable]
   private var currentNewsItem:NewsVO;

   mx:DateFormatter id=newsDateField_fmt formatString=DD/MM/ /

   mx:DateField id=newsDate_dfield
text={newsDateField_fmt.format(currentNewsItem.newsDate)}
formatString=DD/MM/
selectedDate={currentNewsItem.newsDate}
/

regards,
Muzak

 On Dec 10, 2007, at 1:22 PM, Todd wrote:

 Hello All,
 I've been trying to wrap my mind around this.
 I have a ValueBoject model that has a date properties and number 
 properties (one of many) that are bound to a TextInput fields on a 
 form.
 What's the best way to handle two-way data validating that the text 
 input has a valid date in it. More importantly, how do you bind a 
 specifically formatted date from the Model.
 Say my model has a valid Date on it, and I want to have it displayed 
 in a textBox as 12/10/2007. The user changes the text box, and then I 
 want the model to have a valid Date object from the input text. The 
 key here is that the format input by a user and the format displayed 
 in the TextInput is different than the raw data that is bound to the 
 model.
 What to do if I bind a new date that hasn't been set in the model yet 
 and I want something like a - (Hyphen) to appear in the form.
 It seems like the default databinding functionality breaks down pretty 
 quickly. What are some of the techniques people use to convert items 
 on a VO object for display purposes in a form, take form input and 
 format it for specific model data?
 Or, do I just need to not use default databinding of my model to form 
 inputs and instead have a method, that takes the VO, and manually 
 binds the data, doing the appropriate conversions as necessary. And 
 then to go the other way, after the form has been filled in and is 
 validated, covert to the model?

 Thanks for any suggestions.



 



--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com
Yahoo! Groups Links




No virus found in this outgoing message.
Checked by AVG. 
Version: 7.5.503 / Virus Database: 269.17.2/1185 - Release Date: 12/15/2007
12:00 PM
 



--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com 
Yahoo! Groups Links

* To visit your group on the web, go to:
http://groups.yahoo.com/group/flexcoders/

* Your email settings:
Individual Email | Traditional

* To change settings online go to:
http://groups.yahoo.com/group/flexcoders/join
(Yahoo! ID required)

* To change settings via email:
mailto:[EMAIL PROTECTED] 
mailto:[EMAIL PROTECTED]

* To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]

* Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
 


Re: [flexcoders] What's the best way to bind ValueOject model data to a form and back again

2007-12-14 Thread Kevin

I have solved this problem this way.

1) Extend a component that you want to use for data entry, such as a  
TextInput component.


2) I add a private property with called _dataProvider OR _dateReference.

3) I then add a public getter ( with the [Bindable] tag if you want  
to allow others to bind to you) and setter for this property


4) In the setter is where you put your business logic related to how  
you want the string to appear in the text box.  You set the text box  
'text property explicitly here.  Because the setter will always get  
called when the bound data changes, you are essentially binding the  
text box to the value as well.


5) Add a valueCommitt, focusOut or change event handler to the  
component so that you can handle the input data.  This handler will  
set your private variable when the user enters some input.


That should do it.  Of course you can extend this further with  
formatters or switch statements to handle different feature...   
etc... but hopefully you get the idea.  It is pretty simple and very  
powerful.


In your view code you will just write something like this.

 MyCustomDateEntry id=myDate dateReference={model.someDate} /

You can bind a Date object from the model, but the text box will show  
whatever you tell it to.  To get the Date back you just use  
myDate.dateReference.


You may also want to check out the DateField control.  It pretty much  
has the functionality you described built into it... with a nice  
calendar to boot.


- Kevin




On Dec 10, 2007, at 1:22 PM, Todd wrote:


Hello All,
I've been trying to wrap my mind around this.
I have a ValueBoject model that has a date properties and number
properties (one of many) that are bound to a TextInput fields on a  
form.

What's the best way to handle two-way data validating that the text
input has a valid date in it. More importantly, how do you bind a
specifically formatted date from the Model.
Say my model has a valid Date on it, and I want to have it displayed
in a textBox as 12/10/2007. The user changes the text box, and then I
want the model to have a valid Date object from the input text. The
key here is that the format input by a user and the format displayed
in the TextInput is different than the raw data that is bound to the
model.
What to do if I bind a new date that hasn't been set in the model
yet and I want something like a - (Hyphen) to appear in the form.
It seems like the default databinding functionality breaks down
pretty quickly. What are some of the techniques people use to convert
items on a VO object for display purposes in a form, take form input
and format it for specific model data?
Or, do I just need to not use default databinding of my model to
form inputs and instead have a method, that takes the VO, and manually
binds the data, doing the appropriate conversions as necessary. And
then to go the other way, after the form has been filled in and is
validated, covert to the model?

Thanks for any suggestions.







Re: [flexcoders] What's the best way to bind ValueOject model data to a form and back again

2007-12-14 Thread Muzak
Use a DateField component for displaying/editing Date type data, in combination 
with a DateFormatter for displaying the right format 
in the DateField textfield.

Not sure if the following will make sense, but here's something I've used:

// in a Script block
// currentNewsItem is a VO retrieved from the Model.
   [Bindable]
   private var currentNewsItem:NewsVO;

   mx:DateFormatter id=newsDateField_fmt formatString=DD/MM/ /

   mx:DateField id=newsDate_dfield
text={newsDateField_fmt.format(currentNewsItem.newsDate)}
formatString=DD/MM/
selectedDate={currentNewsItem.newsDate}
/

regards,
Muzak

 On Dec 10, 2007, at 1:22 PM, Todd wrote:

 Hello All,
 I've been trying to wrap my mind around this.
 I have a ValueBoject model that has a date properties and number
 properties (one of many) that are bound to a TextInput fields on a
 form.
 What's the best way to handle two-way data validating that the text
 input has a valid date in it. More importantly, how do you bind a
 specifically formatted date from the Model.
 Say my model has a valid Date on it, and I want to have it displayed
 in a textBox as 12/10/2007. The user changes the text box, and then I
 want the model to have a valid Date object from the input text. The
 key here is that the format input by a user and the format displayed
 in the TextInput is different than the raw data that is bound to the
 model.
 What to do if I bind a new date that hasn't been set in the model
 yet and I want something like a - (Hyphen) to appear in the form.
 It seems like the default databinding functionality breaks down
 pretty quickly. What are some of the techniques people use to convert
 items on a VO object for display purposes in a form, take form input
 and format it for specific model data?
 Or, do I just need to not use default databinding of my model to
 form inputs and instead have a method, that takes the VO, and manually
 binds the data, doing the appropriate conversions as necessary. And
 then to go the other way, after the form has been filled in and is
 validated, covert to the model?

 Thanks for any suggestions.



 



--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com 
Yahoo! Groups Links

* To visit your group on the web, go to:
http://groups.yahoo.com/group/flexcoders/

* Your email settings:
Individual Email | Traditional

* To change settings online go to:
http://groups.yahoo.com/group/flexcoders/join
(Yahoo! ID required)

* To change settings via email:
mailto:[EMAIL PROTECTED] 
mailto:[EMAIL PROTECTED]

* To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]

* Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/