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]