<snip/>
2) the first, while more verbose, forces you to separate clearly "controller logic" from the "presentation" logic. I wouldn't write it like the above but like
<pipeline internal-only="true"> <match pattern="screen/edit"> <generate src="cocoon://generate"/> <transform src="profileForm.xsl"/> <serialize/> </match> </pipeline>
<pipeline> <match pattern="*/profile/*"> <call function="main"> <param name="action" value="{2}"/> </call> </match> </pipeline>
function main(action) { func = this[action]; if (func != undefined) func.apply(this,args); cocoon.sendPage("screen/" + action); }
function edit() { userID = util.getRequestParam("userID") - 0; userHome = util.lookupHome("User"); user = userHome.findByPrimaryKey(userID); util.set( "user", user.getValueObject() ); }
which seems more verbose, but it's, IMO, much cleaner as the main() method acts as a dispatcher for screens and you can overload them if you need to.
this is the approach that I've used in all my flowscripts and it has been working quite nicely (that is, couldn't find out a cleaner way of doing the same).
Just remember the issue I raised between named parameters in the sitemap and positional arguments in the function declaration: unfortunately it's way too late to forbid this, but it should be discouraged because potentially leading to bugs very difficult to find.
So your main function should be written: function main() { func = this[cocoon.parameters.get("action")]; if (func != undefined) func.apply(this,args); cocoon.sendPage("screen/" + action); }
IIRC, cocoon.parameters["action"] should work also, but I'm not sure.
Sylvain
-- Sylvain Wallez Anyware Technologies http://www.apache.org/~sylvain http://www.anyware-tech.com { XML, Java, Cocoon, OpenSource }*{ Training, Consulting, Projects } Orixo, the opensource XML business alliance - http://www.orixo.com