[Helma-user] Static Skins in prototype
Maksim Lin for technical support mailling lists
maksim_lin at ngv.vic.gov.au
Tue Jul 24 02:18:40 CEST 2007
Hi Anton,
I've needed to do exactly this a few times in the past and the quick
hack I first used was:
(new myProto()).renderSkin("add");
I suspect the reason you want to be able to call static skins on
prototypes is for the same reason I previously asked for having actions
on collections: that is to be able to have a way of creating generic
code that works on collections of all prototypes.
I've recently been working on just this kind of rails-like scaffolding
code and I think I have come up with a reasonable way of doing this in
helma - by using mountpoints extensively.
The design pattern I have come up with is of always defining a _children
for every prototype which is a collection of all the prototypes objects.
So for example:
myProto/type.properties
_children = collection(myProto)
----
then I would do:
Root/type.properties
myprotos = mountPoint(myProto)
----
And now you can now use almost the same code you wanted:
root.myprotos.renderSkin("add");
And if you then define some generic actions like add, edit, delete in
HopObject prototype, you can then have a nice generic way of handling
collections of any prototype without resorting to creating "manager"
prototypes, since you can have urls like:
http://localhost:8080/myapp/myprotos/create (I use "create" instead of
"add")
http://localhost:8080/myapp/myprotos/list
I took this one step further and defined a generic renderPage() function
in HopObject which by default looks for a skin with the same name as the
action and applies some html headers/footers, title/headings etc, so my
action code looks like:
HopObject/create.hac
res.data.title = "Create New "+ this.__prototype__;
if (req.data.submit) {
var nuObj = new global[this.__prototype__];
if (this.processForm(nuObj)) {
this.add(nuObj);
res.redirect(this.href("list")); //redirect back to list page
}
//otherwise the error mesg will be in res.mesage so just render form
page again below
}
this.renderPage();
----
And while I have a generic create.skin in HopObject, you can just put a
more customised one in any of your prototypes. Likewise the generic
processForm() in HopObject can be over-ridden by a custom one if you
need to do special processing on form data for any particular prototype
and finally you can of course create custom create,edit,list, delete
actions in each prototytpe to completely change this default processing.
I'm sorry for the rather long email - I started documenting this in the
helma dev wiki, but ran out of time last week, so I'l copy the above
into there as well and post all my code there too and hopefully others
will be interested in using or even better improving this approach
further...
Maks.
> -----Original Message-----
> From: helma-user-bounces at helma.org
> [mailto:helma-user-bounces at helma.org] On Behalf Of Anton Pirker
> Sent: Tuesday, 24 July 2007 04:31
> To: helma-user at helma.org
> Subject: [Helma-user] Static Skins in prototype
>
> Hi List!
>
> Is it possible to have static skins of prototypes?
> I have the name of a Prototype and want to render an
> add-Form. So i tought it would be nice if i could do
> something like this:
>
> var protoName = "myProto";
> global[protoName].renderSkin("add");
>
> Is there a way to achieve this?
>
>
> thanks in advance,
> Anton
>
> _______________________________________________
> Helma-user mailing list
> Helma-user at helma.org
> http://helma.org/mailman/listinfo/helma-user
>
>
>
More information about the Helma-user
mailing list