Inline... > -----Original Message----- > From: David Rosenstrauch [mailto:[EMAIL PROTECTED]] > Sent: 20 December 2001 16:44 > To: [EMAIL PROTECTED] > Subject: RE: How do I add objects to the objectModel Map > > > I've never used the velocity generator before so I may be > off-base. But IIUC ... If you've never used the VelocityGenerator you're missing something ;)
> > I don't think you generally add objects into the map. > Rather, the map comes pre-populated with objects that your > code needs: request, response, etc. I would like to create an object that provides metadata about the site structure that can be accessed by various Velocity or JSP (or whatever) components. This (these) may also provide interfaces to other business logic. Added stuff to the context - crashed cocoon, tried again - fine. I've even been dropping arbitrary objects into the context and using Velocity driven reflection to monitor them - interesting... > > e.g.: > > public class > YourGenerator extends ComposerGenerator { > > public void > setup(SourceResolver resolver, Map objectModel, String > src, Parameters par) > throws ProcessingException, SAXException, IOException { > super.setup(resolver, objectModel, src, par); > > Request request = > (Request)objectModel.get(Constants.REQUEST_OBJECT); > //System.out.println("request: "+request+"; rtf gen setup > called @ "+new java.util.Date()); > String filename = request.getParameter("filename"); > > > Note how in this generator, you can get a hold of the request > object from out of the object map. Back to the objectModel itself; if it is instantiated on a per-request then I need to figure out where to add it independant of generator used; otherwise, if I put it in the VelocityGenerator then I'd have to put it in the JSPGenerator and the XSP one... > So the "export-object" parameter that you were referring to > is a means of transferring these objects from Cocoon's object > map into a place where velocity can find them. Yep - which is why I want to populate it... > > According to the docs: > > " Default Java objects exported to the Velocity context: > > * request (org.apache.cocoon.environment.Request) - > * The Cocoon current request template (java.lang.String) - > * The path of the template file currently being evaluated > response (org.apache.cocoon.environment.Response) - > * The Cocoon response associated with the current request > context (org.apache.cocoon.environment.Context) - > * The Cocoon context associated with the current request > parameters (org.apache.avalon.framework.parameters.Parameters) - > Any parameters passed to the generator in the pipeline > " > > That seems to pretty much cover most of the important object > map objects that I think you'd want to pass to velocity, so > it doesn't seem like there'd be much need to use this parameter. As I said - business beans and things... I only want to instantiate my menu/arealogic class once so, no, not a generator/transformer; more *like* a generator/transformer, ie at the same time as the <map:generators> section. kinda like: <map:objectModel> <map:object name="menu" src="com.dgreaves.apache.cocoon.ext.Menu" method="newfromfile" data="/areamap.xml" poolsize="10"/> <map:objectModel> > I suppose if you wanted to, though, you could add an object > of your own to the object map (see the generator code above; > you could do this in an action too), and then have that > object get copied over to velocity using the "export-object" parm. exactly... You mentioned actions ... I've not really looked at them yet - do you think that would be fruitful? > Whew! Sorry for being so long winded. Hope this helps. > Best I could do. Someone correct me if I'm wrong. Thanks - it's really helpful. > > > DR > > > At 04:23 PM 12/20/01 +0000, you wrote: > >Anyone? > >Help? > > > > > > > -----Original Message----- > > > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] > > > Sent: 20 December 2001 00:18 > > > To: [EMAIL PROTECTED] > > > Subject: How do I add objects to the objectModel Map > > > > > > > > > Hi > > > > > > I hope this is straightforward... > > > > > > How do I add objects to the objectModel Map? > > > > > > http://xml.apache.org/cocoon/userdocs/generators/velocity-gene > >rator.html > >says: > ><export-object key="objectMapKey" > name="velocityContextName"/> (optional; > >0..n) - Export the object specified by key from the Cocoon > object map to the > >Velocity context of the template. The object can be accessed from the > >template as name. Be careful to use a valid VTL variable name. > > > >I've looked through the code but can't figure this one out. > > > >David > > --------------------------------------------------------------------- Please check that your question has not already been answered in the FAQ before posting. <http://xml.apache.org/cocoon/faqs.html> To unsubscribe, e-mail: <[EMAIL PROTECTED]> For additional commands, e-mail: <[EMAIL PROTECTED]>