> you can communicate values using the Environment class (push and > pop/peek methods)
I considered using the environment for this, but I'm a big proponent of popping what I push; That might be a bit misguided but it's an old habit. > so you dont > have to (ab)use the > dom document for something like this Hmm... I wouldn't have considered this abuse. If your component is going to render something known what's the harm in looking it up later? >> However, this solution will not scale easily for different constraints. If you want your components to put constraints on their usage by a developer then you may want to consider a more involved solution. Probably using an annotation and a transformation to keep track of whatever attributes you want to enforce. Unless you expect the component to be added multiple times but only render once I'd also consider throwing an exception so the developer knows why their second instance didn't render. Perhaps an attribute of your annotation? @ComponentRestrictions(max=1, failHard=true) -- Josh On Sep 16, 2010, at 12:02 AM, Andreas Andreou <[email protected]> wrote: > you can communicate values using the Environment class (push and > pop/peek methods) > or by injecting the ServletRequest and set/getAttribute... so you dont > have to (ab)use the > dom document for something like this > > On Thu, Sep 16, 2010 at 09:17, Alessio Gambi <[email protected]> wrote: >> Hi Josh, >> >> thanks. >> >> As you suggested I defined a special-fixed-component-id for the component >> and I checked before its rendering (during its own SetupRender) if that id >> was already present >> in the document (writer.getDocument().getElementById()). If so I just >> skipped the render (by returning False) and everything is fine. >> >> However, this solution will not scale easily for different constraints. >> Assume for example that you want to force one of the following constraints >> in the page (not all of them may have real use cases): >> >> - N and only N components of the same type, N > 1 >> - No components of type X >> >> I guess you can always work with the Document object and look for some IDs >> (maybe a programmatic way to do that will scale better). >> Moreover, I noticed that apparently the Document object >> (writer.getDocument()) provides only two methods to retrieve elements: >> Element find(String path) [Finds an element >> based on a path of element names.] >> Element getElementById(String id) [Tries to find an >> element in this document whose id is specified.] >> >> and both of them assume that you know precisely what you are looking for, >> and they cannot use of regexp or similar to specify the id and path params. >> >> BTW (maybe OT) >> Can you render a component inside a page or another component that has no >> template at all? >> >> Something like this. >> Container Component Class{ >> >> private ContainedComponent myComponent; >> >> @BeginRender >> public void render(MarkupWriter markupWriter){ >> markupWriter.render( myComponent ); >> } >> } >> >> I tried adding the @Component annotation and returning the object in the >> different rendering methods, but it didn't work. >> >> Thanks again. >> -- Alessio >> >> > > > > -- > Andreas Andreou - [email protected] - http://blog.andyhot.gr > Tapestry PMC / Tacos developer > Open Source / JEE Consulting > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [email protected] > For additional commands, e-mail: [email protected] > --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
