Re: Reference current session...common accessor ??
Re: Reference current session...common accessor ??
- Subject: Re: Reference current session...common accessor ??
- From: Kieran Kelleher <email@hidden>
- Date: Fri, 1 Jul 2005 13:24:29 -0400
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:
email@hidden
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