From: Marc v. de G. <mvd...@xs...> - 2002-11-25 21:39:02
|
<< Removed irrelevant text >> > You don't really want to subclass WebContext. Instead, you want to > make helper classes or tools (by implementing org.webmacro.ContextTool > and configuring it via webmacro.properties). If you have some kind of > Jetgen tool, you can use it via your templates like this: > $Jetgen.Records > $Jetgen.LastQuery > $Jetgen.Whatever ## i've never used Jeetgen, so I don't really > know what it does. :) > > And from your sevlet code, you can access your Jetgen tool like this: > JetgenTool jetgen = (JetgenTool) context.get("Jetgen"); > jetgen.getRecords(); > jetgen.getLastQuery(); > jetgen.getWhatever(); > And if you don't like the ContextTool approach, you can just .put the > object into the context: > context.put ("Jetgen", new JetgenTool()); I thought of that, but before I pass the field values over to the template, I do want to do some formating of several values (e.g. dates values from the yyyy-mm-dd format to the dd-mm-yyyy format). I do not want to do that in the template. So, although I tried it, this is not an option for me. > > The problem is: there are so many final classes, that I'm wondering if > > it is > > possible to do this. Especially the newInstance method. Can somebody > > give me > > tips on how to do this so I can use that WebContext subclass in the > > WMServlet subclass I've already created? Or is there some other > > approach > > somebody can recommend for this problem? > > Btw, there is already an http request form tool > (org.webmacro.servlet.FormTool) that is configured by default. Access > it from your templates as $Form, and from your code as: > servletContext.getForm() > > Lots of things in WM are final on purpose. The idea of WM is not to > allow you to directly extend and subclass it, but to allow you to > extend its functionality by creating tools that aren't (really) > specific to WebMacro... and to use your existing classes and objects > w/o change. This way, WebMacro stays focused on what it does best: > template rendering, and you can focus on your application w/o worrying > about implementation details of WM. I think I will go for this option. It is flexibele and I can add it or not in future projects without much trouble. Thanks for the advice. Next problem is how am I going to create a Tool class: www.webmacro.org, here I come for another visit... Regards, Marc |