From: Eric B. R. <eb...@tc...> - 2002-11-25 15:17:24
|
On Monday, November 25, 2002, at 03:21 AM, Marc van de Geijn wrote: > First of all: I'm new to WebMacro (using it for a week now) and the > more I > get to know it, the more I like it. Great job! We're glad you like it. > What I'm trying to do is: At one side there are the WebMacro classes > for > processing the Web requests and responses, on the other the Jetgen > classes > (http://www.jetools.com) for access to the database. > > I've got both up and running. Somehow I want to make the conversion of > the > data from the jetgen classes into the WebMacro classes easy. I was > thinking > about subclassing the WebContext class to add methods to do just that. > I > already have a subclass of WMServlet to do some basic stuff with form > data. 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()); > 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. eric |