Okay, so I'm finally getting around to implementing this in the app I'm working on, but am having an issue now when I try to switch from using dateformat in my component to using formatter.

Basically, everything displays okay, but when I try to make changes and save them I get this error:

IllegalArgumentException: While trying to invoke the set method "public void com .mobilewarrior .model ._ActivitySchedule .setStartDate(com.webobjects.foundation.NSTimestamp)" on an object of type com.mobilewarrior.model.ActivitySchedule we received an argument of type java.util.Date. This often happens if you forget to use a formatter.

My component looks like the following:
<wo:textfield class="date-time" value="[activitySchedule.startDate]" formatter="[scheduleDateFormatter]" />

And my schedule date formatter looks like this:
        public SimpleDateFormat scheduleDateFormatter() {
SimpleDateFormat dateFormatter = new SimpleDateFormat("MMMM d, yyyy hh:mm a");
                TimeZone tz = ((Session)session()).timeZone();
                dateFormatter.setTimeZone(tz);

                log.debug("  format = " + dateFormatter.toPattern());
log.debug(" timezone = " + dateFormatter.getTimeZone().getDisplayName());
                return dateFormatter;
        }

So...if my model object is storing it's value as NSTimestamp, but SimpleDateFormat.parse() return a Date object...this isn't going to work very well.

How do you guys do it? Use the deprecated NSTimestampFormatter instead? Build cover methods to convert from Date to NSTimestamp? Something else?

        - Leif

On Apr 15, 2009, at 4:51 AM, Travis Britt wrote:


On Apr 14, 2009, at 9:04 PM, Andrew Lindesay wrote:
I'm not sure what that value is used for in the EOModel -- anybody know?

I think Mike and I looked into this several months ago and turns out it isn't actually used, tho it is documented in EOAttribute as being implemented in EOAdaptorChannel. IIRC it exists in EntityModeler b/c it was in EOModeler.

On Apr 14, 2009, at 8:46 PM, Leif Harrison wrote:
3. How can I get the local timezone (of the browser client) so that I can use it for my WOTextfield formatters (to display local time)?

The time zone in your app and database server should be the same. I recommend setting it explicitly in the app. (Don't rely on using the runtime's default since this changes based on the server's time zone.) Just use GMT! But I believe this should all work so long as everything is operating with the same time zone. (For example, if you have legacy data stored with a time zone region like America/New York it's not easy to convert it accurately to GMT due to changes in DST.) You do not want dates stored in the DB with different time zones.

Wen a user logs in to the app you can snag their browser's gmt offset by using javascript to write out a hidden form field something like this:

<script>
document.write('<input type="hidden" name="gmtOffsetMinutes" value="' + new Date().getTimezoneOffset() + '" />');
</script>

Then your login method can grab that as an integer, create a TimeZone object from it and stash it somewhere handy (like Session.)

I create a TimeZone object from the gmt offset using TimeZone.getTimeZone(String) with a string created by prepending "GMT-" or "GMT+" to the offset value in hours. (Note that the Javascript will give it to you in minutes.)

Then you can use the TimeZone obj in your formatter to display the date in the user's time zone. Works great.

tb

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      ([email protected])
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/rexfelis%40catsreach.org

This email sent to [email protected]

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      ([email protected])
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to