• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: ERXThreadStorage and willUpdate()
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: ERXThreadStorage and willUpdate()


  • Subject: Re: ERXThreadStorage and willUpdate()
  • From: Chuck Hill <email@hidden>
  • Date: Mon, 4 Oct 2010 15:01:25 -0700

I usually make a another class, e.g. K12Thread and then add static methods on that do my casting etc.  e.g.

    public static User user(EOEditingContext ec)
    {
        return isAttached() ? ((User)ERXThreadStorage.valueForKey(USER_KEY)).localInstance(ec) : null;
    }

Which results in:

> willUpdate() {
> 	super.willUpdate();
> 	setModifiedBy(K2Thread.user(editingContext());
> }


You could also add this in K12GenericRecord or a suitable superclass:

    public User activeUser()
    {
        return K2Thread.user(editingContext();
    }


And then in your code:

> willUpdate() {
> 	super.willUpdate();
> 	setModifiedBy(activeUser());
> }



On Oct 4, 2010, at 1:22 PM, David Avendasora wrote:

> Hi all,
>
> We are moving from having to remember to manually set the modifiedBy and modifiedDate values in our EOs when they are modified to overriding willUpdate() and pulling the loggedInUser from ERXThreadStorage.
>
> We are overriding willUpdate() in our K12GenericRecord which all our EOs extend.
>
> for example (very simplified to get the point across) :
>
> willUpdate() {
> 	super.willUpdate();
> 	setModifiedBy((SystemUser) ERXThreadStorage.valueForKey("loggedInUser"));
> }
>
> As you can see, we are casting the results of the ThreadStorage as SystemUser which itself is a subclass of K12GenericRecord.
>
> It seems odd to be importing a subclass into it's own superclass, but it since a SystemUser really is a standard EO and therefor is-a K12GenericRecord, it also seems correct.
>
> We're not doing anything horribly wrong here, are we?
>
> Dave _______________________________________________
> 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

--
Chuck Hill             Senior Consultant / VP Development

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







Attachment: smime.p7s
Description: S/MIME cryptographic signature

 _______________________________________________
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

References: 
 >ERXThreadStorage and willUpdate() (From: David Avendasora <email@hidden>)

  • Prev by Date: WODIsplyGroup, sort ordering after qualifyDisplayGroup
  • Next by Date: Re: ERXThreadStorage and willUpdate()
  • Previous by thread: Re: ERXThreadStorage and willUpdate()
  • Next by thread: WODIsplyGroup, sort ordering after qualifyDisplayGroup
  • Index(es):
    • Date
    • Thread