Re: Chuck Hill's quite good Practices, WOWODC 08
Re: Chuck Hill's quite good Practices, WOWODC 08
- Subject: Re: Chuck Hill's quite good Practices, WOWODC 08
- From: Chuck Hill <email@hidden>
- Date: Tue, 21 Jul 2009 17:34:10 -0700
On Jul 21, 2009, at 5:24 PM, Miguel Angel Torres Avila wrote:
On Jul 21, 2009, at 7:10 PM, Chuck Hill wrote:
Hi Miguel,
On Jul 21, 2009, at 4:53 PM, Miguel Angel Torres Avila wrote:
Hi guys,
I am staring a new project and I want to use Wonder and try to
implement Chuck Hill's recommended best practices.
I have watched a lot of times (almost 10 times) the screencast
http://www.wocommunity.org/podcasts/WOWODC08_BestPratices.mp4
And I am trying to implement his recommendations about Page
Inheritance.
First we have this diagram.
<Picture 2.png>
And this is the justification for doing that.
<Picture 3.png>
At this time I am focusing on the editingContext method.
I have created a Java Class called CommonPage:
import com.webobjects.appserver.WOContext;
import com.webobjects.eocontrol.EOEditingContext;
import er.extensions.components.ERXComponent;
import er.extensions.eof.ERXEC;
@SuppressWarnings("serial")
public class CommonPage extends ERXComponent {
/**
*EditingContext
*/
protected EOEditingContext ec = null;
I'd make that private so that use of editingContext() is enforced.
You are totally right, my mistake.
public CommonPage(WOContext context) {
super(context);
ec = ERXEC.newEditingContext();
}
public EOEditingContext editingContext(){
return ec;
}
}
As you can see it is extending from ERXComponent, I just added an
Editing Context an a method to get it.
Next, Chuck talks about the importance of creating a
CommonComponent Class
<Picture 1.png>
And this is the justification:
<Picture 4.png>
As far as I can understand (English is not my natural language)
the idea is to create a method editingContext() that returns the
Page editing Context.
I am confused at this point. Based on the diagram CommonComponent
inherits from CommonPage so, it has its own editing context
because CommonPage creates a new one on its constructor.
Cough. Yes. Well. er. The diagram is wrong. Congratulations,
you are the only one to have noticed this! Including me... :-(
CommonPage and CommonComponent should have the same super-class.
You can use ERXComponent for this or subclass ERXComponent and make
your own custom super class.
public CommonPage(WOContext context) {
super(context);
ec = ERXEC.newEditingContext();
}
I think the idea of a CommonComponent is to use it on every
"subComponent" of my application, and the idea of a
editingContext() method on the CommonComponent is to get the
editing Context of the Page that is wrapping the SubComponent, in
other words, the SubComponent's father.
That is correct.
Ok, I have the idea but I can not figure out how to accomplish it.
OK, let's use some exact names. You are using ERXComponent. You can
sub-class this as CustomComponent. In CustomComponent, you can have
this method (and anything else that you want to add):
public abstract EOEditingContext editingContext();
For top level pages, you will sub-class CustomComponent as CommonPage
and implement editingContext() as:
public CommonPage(WOContext context) {
super(context);
ec = ERXEC.newEditingContext();
}
public EOEditingContext editingContext(){
return ec;
}
For components that you will use on CommonPage, you will sub-class
CustomComponent as CommonComponent and implement editingContext() as:
public EOEditingContext editingContext(){
return ((CommonPage)context().page()).editingContext();
}
Or, you can allow for components to possibly have their own editing
context (with more than one EC on a page) and implement it like this:
public EOEditingContext editingContext(){
return ((CustomComponent)parent()).editingContext();
}
Does that make sense?
Chuck
In the screencast you suggest a method like this:
public EOEditingContext editingContext(){
return ((PageClass)context().page()).editingContext();
}
If I understand it, this a generic example. The intention is to
create a method like this in my CommonComponent subclass, for
example, editUser that will be wrapped for a ControlUser Component.
It would be something like this
public EOEditingContext editingContext(){
return ((ControlUser)context().page()).editingContext(); /// I
am not sure how this would work
}
That way if ControlUser inherits from CommonPage i has its own
edtingContext.
But if I want to make reusable my editUser component that would not
be useful.
Or is there a way to create a method in the CommonComponent that
returns the editing context of the page that is wrapping it, if so
could you give me an example?
Thanks Chuck, the screencast is really interesting, once I
understand this I will ask for help on other areas that you mention.
In all my projects, before using Wonder and before trying to
implement Chuck's best practices I used to create a new
EditingContext in my principal Component and pass it to the
subcomponent through bindings. That way the main component (Page)
has the editinContext control.
I just want to know if my interpretation of the screencast is
correct or I am misunderstanding it. If I am understanding, could
someone explain me how the editingContext() method in the
ComonComponent would work?
Your English is fine. It is my diagrams that need help.
Chuck
--
Chuck Hill Senior Consultant / VP Development
Learn WO at WOWODC'09 East in Montréal this August!
http://www.wocommunity.org/wowodc09/east
http://arstechnica.com/apple/news/2009/07/webobjects-sliced-from-106but-prognosis-of-death-premature.ars
--
Chuck Hill Senior Consultant / VP Development
Learn WO at WOWODC'09 East in Montréal this August!
http://www.wocommunity.org/wowodc09/east
http://arstechnica.com/apple/news/2009/07/webobjects-sliced-from-106but-prognosis-of-death-premature.ars
_______________________________________________
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