Hi all,
What do you think of current approach?
I have defined a mainController which gets one parameter, the name of
the specific page controller (previewController.js). It loads the
script and calls the main() method of the previewController which
extends the PageController.
I only need to specify the view and call showPage(). I also inherit the
general application pageData and can add more data specific for the
view.
Cheers,
Robby Pelssers
<!--+
| Definition of the control flow implementation.
+-->
<map:flow language="javascript">
<map:script src="controllers/mainController.js" />
</map:flow>
<map:match pattern="preview.html">
<map:call function="_loadPage">
<map:parameter name="script" value="previewController.js"/>
</map:call>
</map:match>
******************** mainController.js *******************************
/**
* Author: Robby Pelssers
*/
var global = this;
function _loadPage() {
try {
_loadScript("controllers/" + cocoon.parameters["script"]);
main();
} catch(ex) {
print(ex.toString());
}
}
function _loadScript(script) {
var resolver =
cocoon.getComponent(Packages.org.apache.cocoon.environment.SourceResolve
r.ROLE);
var src = resolver.resolveURI(script);
cocoon.load(src.getURI());
resolver.release(src);
}
function PageController(view) {
this.view = view;
this.initialize();
}
PageController.prototype.initialize = function() {
this.pageData = {};
this.pageData.application = cocoon.getComponent("application");
}
PageController.prototype.getRequestParameter = function(name) {
return cocoon.request.getParameter(name);
}
PageController.prototype.getSitemapParameter = function(name) {
return cocoon.parameters[name];
}
PageController.prototype.showPage = function() {
cocoon.sendPage(this.view , this.pageData);
}
******************** previewController.js **************************
/**
* Author: Robby Pelssers
*/
function main() {
new PreviewController("views/preview.html").showPage();
}
//PreviewController extends PageController
PreviewController.prototype = new PageController();
PreviewController.prototype.constructor = PreviewController;
function PreviewController(view) {
PageController.call(this, view);
}
*********************************************************************