Re: binding a form value to a NSTimestamp field
Re: binding a form value to a NSTimestamp field
- Subject: Re: binding a form value to a NSTimestamp field
- From: WebObjects <email@hidden>
- Date: Tue, 18 Apr 2006 10:58:50 -0700
- Thread-topic: binding a form value to a NSTimestamp field
Chuck/Ken/All,
Awesome recommendations. I realize that soon to follow will be arguments
that exceptions should not be used as part of a designed flow control - but
before they hit I'd like to say thanks, this is the solution I needed.
-Bill
on 4/18/06 10:53, Ken Anderson at email@hidden wrote:
> If you have users in multiple time zones, you could put the shared
> formatter in the session instead (same easy access), and then have it
> formatted to the user's timezone.
>
> Ken
>
> On Apr 18, 2006, at 1:46 PM, Chuck Hill wrote:
>
>> I won't claim there is one best way. Here is how I have been
>> handling these. First off, stop using dateFormat/numberFormat.
>> They are easy to use, but as you have seen, no help at all in
>> validating input. They are OK for output. So, what to use
>> instead? There is a formatter binding also available and I find
>> that works much better. You will then be able to catch the
>> exception in your page (in validationFailedWithException I believe)
>> and handle it.
>>
>> In order to make these easier to use, I usually declare them at the
>> application level using one of many variants of this:
>>
>> protected static final NSTimestampFormatter dateFormatter = new
>> NSTimestampFormatter("%m/%d/%y");
>>
>> public NSTimestampFormatter dateFormatter() {
>> return Application.dateFormatter;
>> }
>>
>> This makes it easy to bind as in:
>>
>>> TextField5: WOTextField {
>>> dateformat = application.dateFormat;
>>> value = newDonor.dtDob;
>>> }
>>
>>
>> HTH
>> Chuck
>>
>>
>>
>> On Apr 18, 2006, at 8:55 AM, WebObjects wrote:
>>
>>> There's always an easier and better way, so why not ask? (right?)
>>>
>>> I have a field in my form for collecting someone's date-of-birth.
>>> The value
>>> will store as an NSTimestamp in the dbase.
>>>
>>> public void setDtDob(NSTimestamp value) {
>>> takeStoredValueForKey(value, "dtDob");
>>> }
>>>
>>> Q: What is the best way to validate the users input, or get it to
>>> conform
>>> to what NSTimestamp will accept for a valid date format?
>>>
>>> I have the field formatted like so:
>>>
>>> TextField5: WOTextField {
>>> dateformat = "%m/%d/%y";
>>> value = newDonor.dtDob;
>>> }
>>>
>>> ...however, this does nothing to protect me from a user who
>>> insists in
>>> typing gobbly-goop into the field. I suppose a series of dropdown
>>> elements
>>> could help enforce input, but I'd rather use a way of catching the
>>> exception
>>> (here is the exception when user-input cannot be parsed):
>>>
>>> [2006-04-18 08:19:52 PDT] <WorkerThread12> Validation failed on an
>>> object
>>> [java.lang.String] with keypath = newDonor.dtDob and exception:
>>> Format.parseObject(String) failed
>>>
>>> Does anyone have a good method written for testing the String in a
>>> field
>>> against a formatting (ie. "%m/%d/%y") ?
>>>
>>> TIA,
>>> -Bill
>>>
>>>
>>> _______________________________________________
>>> Do not post admin requests to the list. They will be ignored.
>>> Webobjects-dev mailing list (email@hidden)
>>> Help/Unsubscribe/Update your Subscription:
>>> 40global-village.net
>>>
>>> This email sent to email@hidden
>>
>> --
>> Coming in late 2006 - an introduction to web applications using
>> WebObjects and Xcode http://www.global-village.net/wointro
>>
>> Practical WebObjects - for developers who want to increase their
>> overall knowledge of WebObjects or who are trying to solve specific
>> problems. http://www.global-village.net/products/
>> practical_webobjects
>>
>>
>>
>>
>> _______________________________________________
>> Do not post admin requests to the list. They will be ignored.
>> Webobjects-dev mailing list (email@hidden)
>> Help/Unsubscribe/Update your Subscription:
>> 40anderhome.com
>>
>> This email sent to email@hidden
>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden