Hi Alex,
> Actually, the component itself now generates a new id correctly (using > the solution that was suggested). Your component actually hasn't gotten a new id, you've just generated a unique id based on your component's id. This is a good thing because if you had several images that you were generating in a single rendering of your component, you might want to generate several unique ids to refer to those images (perhaps an independent legend image?). You wouldn't want a new instance of your component created every time you created a unique id, right? Since you want to generate the charted data in the page request, and not the image request, you need to store that data somehow. It sounds like you were hoping that Tapestry would automatically know what data you wanted stored per rendering of your component, as opposed to per instance as it works now. Since the loop doesn't actually create a new instance of your compenent for every iteration, you are going to have to make your component understand what it means to be rendered in a loop. This most likely means storing the data in a map during the page render request so that the data can be pulled back out of the map during the image render request. You can persist this map in the component using @Persist. It's not ApplicationState, it's page state and it sounds like you do want your chart rendering to depend on page state. Doing things this way makes your image links require a page render before they will work. If you want to allow people to pass around links to the images then they'll fail outside of the page because the data won't be there to recreate them. Josh On Feb 5, 2008 3:39 AM, Alexander Lamb <[EMAIL PROTECTED]> wrote: > Actually, the component itself now generates a new id correctly (using > the solution that was suggested). > > As you can see in the HTML generated: > > <div><img id="toto_1" onclick="window.open('./ > statistics.dashboardview.enrollmentbenchmarkchart.toto:chart/ > 920/560','_blank','width=944, height=584')" src="./ > statistics.dashboardview.enrollmentbenchmarkchart.toto:chart/460/280" > style="cursor:pointer"><div></div></div><br> > <div><img id="toto_2" onclick="window.open('./ > statistics.dashboardview.enrollmentbenchmarkchart.toto:chart/ > 920/560','_blank','width=944, height=584')" src="./ > statistics.dashboardview.enrollmentbenchmarkchart.toto:chart/460/280" > style="cursor:pointer"><div></div></div><br> > <div><img id="toto_3" onclick="window.open('./ > statistics.dashboardview.enrollmentbenchmarkchart.toto:chart/ > 920/560','_blank','width=944, height=584')" src="./ > statistics.dashboardview.enrollmentbenchmarkchart.toto:chart/460/280" > style="cursor:pointer"><div></div></div> > > The id of the img is correctly incremented (toto_1, 2, 3...) But the > source of my image has always the same url: > "./statistics.dashboardview.enrollmentbenchmarkchart.toto:chart/460/280" > That was built using "createActionLink" > What I was expecting was: > "./statistics.dashboardview.enrollmentbenchmarkchart.toto_1:chart/ > 460/280" > "./statistics.dashboardview.enrollmentbenchmarkchart.toto_2:chart/ > 460/280" > etc... > The problem seems to be related to the fact "getCompleteId" does not > generate a new id. > Now, obviously, I could put the data of my graph in my application > state then pass a context at the end of the url (after the 460/280) > then use that context to fetch the data from within my graph. However, > I feel this is not very good design. After all, if I have a loop with > several graphs being generated dynamically, I simply want to create as > many statefull graph objects as there are rows in my loop, each object > containing the data to draw, without binding strongly with an > application state. > > Alex > Le 4 févr. 08 à 19:06, Chris Lewis a écrit : > > > It's difficult to respond as clearly we're not seeing all of the > > code, but here one would assume that your custom component, in terms > > of generated markup, is simply an img element. No action link will > > have your generated id because you're not creating one in this code. > > Rather you create and output only and img with the id generated by > > T5, so if you look at the generated markup you should see the id > > being correctly incremented, but it will be an attribute of the img > > (and NOT a (action)link), because you aren't doing that in this code. > > > > Alexander Lamb wrote: > >> Well, getting close, but not quite. > >> > >> Indeed, the getClientId works fine, but since my component is > >> actually a graph (JFreeChart) being rendered from an URL, it looks > >> like the clientId is not pushed to the ActionLink created. > >> > >> @SuppressWarnings("unchecked") > >> void beginRender(MarkupWriter writer) { > >> _clientId = _renderSupport.allocateClientId(_resources.getId()); > >> System.out.println("--- CLIENT ID: " + _clientId); > >> System.out.println("--- RESOURCES ID: " + _resources.getId()); > >> System.out.println("--- RESOURCES COMPLETE ID: " + > >> _resources.getCompleteId()); > >> //generate action link > >> Link link = _resources.createActionLink("chart", false, > >> _width, _height); > >> Element img = writer.element("img", "src", link, "id", > >> _clientId); > >> > >> if(_popupWidth == 0) > >> _popupWidth = 2 * _width; > >> if(_popupHeight == 0) > >> _popupHeight = 2 * _height; > >> link = _resources.createActionLink("chart", false, > >> _popupWidth, _popupHeight); > >> img.attribute("onclick", "window.open('"+link > >> +"','_blank','width="+(_popupWidth+24)+", height="+(_popupHeight > >> +24)+"')"); > >> img.attribute("style", "cursor:pointer"); > >> > >> _resources.renderInformalParameters(writer); > >> } > >> > >> > >> My trace and the HTML source generated shows very well the clientId > >> is incremented correctly... but the ActionLink generated is not > >> (completeId stays always as the initial id). > >> > >> Alex > >> > >> Le 4 févr. 08 à 15:45, Chris Lewis a écrit : > >> > >>> Alex, > >>> > >>> Id generation, as far as I know, does not come for free. If you > >>> want to receive an id generated by T5, you have to explicitly > >>> request it. You'll find this done in one of the parent classes of > >>> the field elements - possibly in AbstractField. I've implemented > >>> it the same way in several different components, one of which you > >>> can see here: > >>> > >>> > http://code.google.com/p/gc-tapestry-components/source/browse/trunk/gc-tapestry5-components/src/main/java/net/godcode/t5c/components/SlideShow.java > >>> > >>> The key parts are: > >>> > >>> @Inject > >>> private ComponentResources resources; > >>> @Environmental > >>> private PageRenderSupport renderSupport; > >>> /** The client-side id. */ > >>> private String clientId; > >>> /* Render phase. */ > >>> @SetupRender > >>> void setupRender() { > >>> clientId = > >>> renderSupport.allocateClientId(resources.getId()); > >>> } > >>> > >>> And then making sure you insert clientId into your component tag's > >>> id attribute. This could probably be isolated into a mixin, or you > >>> could probably just extend AbstractField. That would make sense as > >>> long as your component's behavior merits the semantics of a field > >>> (which it doesn't seem to). > >>> > >>> Hope that helps. > >>> > >>> chris > >>> > >>> > >>> Alexander Lamb wrote: > >>>> Hello list, > >>>> > >>>> It looks like custom components are not statefull. > >>>> > >>>> Indeed, I have a loop which contains a graph I generate and a > >>>> TextField (for testing purposes), and the generated code looks > >>>> like this: > >>>> > >>>> <div><img src="./ > >>>> statistics > >>>> .dashboardview > >>>> .enrollmentbenchmarkchart.monthserieslinechart:chart/460/280"></ > >>>> div></div></td></tr><tr><td><input id="textfield_8" > >>>> name="textfield_8" type="text" value="ITALY"><img alt="[Error]" > >>>> class="t-error-icon t-invisible" id="textfield_8:icon" > >>>> src="assets/tapestry/field-error-marker.gif"><div> IT <div><img > >>>> src="./ > >>>> statistics > >>>> .dashboardview > >>>> .enrollmentbenchmarkchart.monthserieslinechart:chart/460/280"></ > >>>> div></div></td></tr><tr><td><input id="textfield_9" > >>>> name="textfield_9" type="text" value="NETHERLANDS"><img > >>>> alt="[Error]" class="t-error-icon t-invisible" > >>>> id="textfield_9:icon" src="assets/tapestry/field-error- > >>>> marker.gif"><div> NL <div><img src="./ > >>>> statistics > >>>> .dashboardview > >>>> .enrollmentbenchmarkchart.monthserieslinechart:chart/460/280"></ > >>>> div></div></td></tr><tr><td><input id="textfield_10" > >>>> name="textfield_10" type="text" value="NORWAY"><img alt="[Error]" > >>>> class="t-error-icon t-invisible" id="textfield_10:icon" > >>>> src="assets/tapestry/field-error-marker.gif"><div> NO > >>>> As you can see, my TextField gets incremented but not my > >>>> enrollmentbenchmarkchart ! > >>>> Should I file a bug for this? > >>>> P.S. I tried to generate the ids but it didn't work. > >>>> Thanks, > >>>> > >>>> Alex > >>>> > >>>> --------------------------------------------------------------------- > >>>> 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] > >>> > >> > >> > >> --------------------------------------------------------------------- > >> 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] > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > -- -- TheDailyTube.com. Sign up and get the best new videos on the internet delivered fresh to your inbox.