• 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: Reference current session...common accessor ??
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Reference current session...common accessor ??


  • Subject: Re: Reference current session...common accessor ??
  • From: Nathan Walker <email@hidden>
  • Date: Fri, 1 Jul 2005 18:32:10 -0400

Thanks for the info and pointers. Subclass we go...

On Jul 1, 2005, at 1:24 PM, Kieran Kelleher wrote:

Subclass WOComponent ..... don't worry about it!

Having a common superclass for all your components that has common functionality that saves you the drudgery of typing the same old boring code statements over and over is good. That's the beauty of OOP in that when we find ourselves doing repeated drudgery, then it's time to abstract the drudgery and refactor our design so that we do only fun stuff and the drudgery is taken care of by common superclasses!

For example.....

public class AnyComponent extends WKComponent{

}

Put your common code in WKComponent, for example.......

import com.webobjects.foundation.*;
import com.webobjects.appserver.*;
import com.webobjects.eocontrol.*;
import com.webobjects.eoaccess.*;

/** A subclass of WOComponent that implements frequently used functionality in
my custom webobjects components. Functionality here should be applicable to
ALL components including page-level and stateless non-syncronizing sub-components */
public class WKComponent extends WOComponent {


<snip>
.....
</snip>

    public WKComponent(WOContext context) {
        super(context);
    }

    /** @return the current session's defaultEditingContext */
    protected EOEditingContext defaultEditingContext() {
        return mySession().defaultEditingContext();
    }

    /** @return Session casted current WOSession */
    public Session mySession() {
        return (Session)session();
    }

    /** @return Application casted WOApplication */
    public Application myApplication() {
        return (Application)WOApplication.application();
    }

    /** Method to automatically convert comma-delimited strings
        into NSArray allowing NSArray bindings to bind to an NSArray
        or simply to be typed as comma-delimited strings.
        @return the array value for <code>bindingName</code> */
    protected NSArray arrayBindingNamed( String bindingName ) {
        Object value = valueForBinding( bindingName );

if (value == null ) {
return null;
} else if (value instanceof NSArray) {
return (NSArray)value;
} else if ( value instanceof String ) {
return NSArray.componentsSeparatedByString( (String) value,",");
} else {
String message = this.name() + "'s binding named '" + bindingName + "' must refer to an NSArray or comma-seperated String!";
throw new RuntimeException( message );
}
}


<snip>
.....
</snip>
}



___________________________________
Kieran Kelleher
Palm Harbor, Florida USA

On Jul 1, 2005, at 11:03 AM, Nathan Walker wrote:


I have these declarations all over:

Session sess = (Session)session();

In order to set things in the current session. I know I could create a superclass with that in it and just have all my components subclass that but seems unneccessary. Am I missing something here. I use this in the Direct Action class a lot to. Do I really have to declare that at the top of all my class files that I intend to reference my session object? It seems so common to set stuff on the current session. There must be someway else..

Thanks,
nathan
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40mac.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
References: 
 >Reference current session...common accessor ?? (From: Nathan Walker <email@hidden>)
 >Re: Reference current session...common accessor ?? (From: Kieran Kelleher <email@hidden>)

  • Prev by Date: Re: PWO - Newbie can't figger out eclipse....
  • Next by Date: Re: PWO - Newbie can't figger out eclipse....
  • Previous by thread: Re: Reference current session...common accessor ??
  • Next by thread: MEETING: Chicago - Tuesday, July 5th
  • Index(es):
    • Date
    • Thread