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.
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/easthttp://arstechnica.com/apple/news/2009/07/webobjects-sliced-from-106but-prognosis-of-death-premature.ars