Quick-Tip: compute the ID of a custom tag (video included)

Thursday, July 9, 2015 at 7:38 AM UTC

Yesterday I accidently found out that you can compute the ID of the rendered HTML element even when you use an XSP element to produce your output tag, e.g. a UL. To produce such a tag you can use a panel:

<xp:panel tagName="ul"></xp:panel>

If you need a computed ID for the outout tag you can have it by defining an attribute:

<xp:panel tagName="ul">

<xp:this.attrs>

<xp:attr><![CDATA[#{javascript:foo.getComputedId()}]]></xp:attr>

</xp:this.attrs>

</xp:panel>

I didn't expect this to be working as the ID is the "holy cow" in XSP but it works. What of course you can not do is then to define the static ID of the panel itself with the XSP attribute "id" - just saying Winken

In general this might be useful when you have such an element within a repeat container and you want to compute the ID from the indexVar. IDs are useful when you want to access them via client side Javascript.

What will not work is to use partial refreshes with your own IDs such as XSP.partialRefreshGet() method. These only work with the XSP IDs computed from the runtime.







Leave a comment right here