Don't you discover the strangest things when browsing through source code?
The other day I ended up in the file "wm.tld", the tag library descriptor file for the WebManager tag library. It defines the tags that we use in JSP to get information from WebManager. Incidentally, this file can be used by Eclipse to help you with tag completion and validation.
One of the tags defined there is <wm:link>. This is a very important tag as it allows you to construct valid links. Building a link is not as straightforward as it may sound. Even if you have the id of a page... What if the site uses friendly URLs? What if the page was dumped to static HTML? What if the page no longer is public? The <wm:link> tag requires some parameters from you and then constructs a valid link to whatever you want to link to.
If you are building a link in your JSP and you find yourself typing a URL, you are probably on the wrong path. Use <wm:link> instead!
The attributes below were taken from the Tag Library Quick Reference.
The Tag Library Quick Reference and Eclipse help me a lot in programming JSPs.
Peachy!
One of the features of the <wm:link> tag is that you can use your own attributes to add parameters to the querystring of the resulting URL.
<%-- Should be like "/web/Test.htm?pi=31415&e=21718" --%>
<wm:link var="test" pi="31415" e="21718" />
${test.url}
Very handy! Now I can create official URLs _and_ pass on my own stuff at the same time.
Upon examining the source from one of the free example WCBs I encountered the following code:
<wm:link var="replyLink"
dbid="${topicId}"
typeofpage="${messageTypeOfPage.id}"
anchor="message${reply.id}"
pagenr="${pageNumber}"
absoluteurl="true"
ignorePersonalization="true" />
The resulting URL looked like:
http://127.0.0.1:8080/web/Forum-test/Lets-see-how-this-works.htm?pagenr=4#message42
Wait a minute... Only the "pagenr" attribute is being shown in the URL! There are a couple of attributes of the wm:link tag that seem to have vanished into thin air:
If these attributes are not passed on, it can only mean they are somehow being picked up and handled by the <wm:link> tag.
But what do they do?
I have dug up the 411 on some of these secret attributes!
The combination of the attributes dbid and typeofpage is used to uniquely identify a database item. The typeofpage indicates the database page model and the dbid indicates the item within that model.
Database page models can be identified by their value, e.g. with the code below:
<c:forEach var="typeOfPage" items="${website.resourceEntities}">
<c:if test="${typeOfPage.identifier == 'forummessage'}">
<c:set var="messageTypeOfPage" value="${typeOfPage}" />
</c:if>
</c:forEach>
Now here's a useful attribute if I ever saw one! The anchor attribute allows you to add an anchor reference at the end of a URL.
Behold this short example JSP:
<wm:link var="test"
anchor="downbelow"
linkText="Jump down!">
${test.htmlTag}
<br/><br/><br/><br/><br/><br/><br/><br/>
<br/><br/><br/><br/><br/><br/><br/><br/>
<a name="downbelow">This is way below.</a>
The result will be a link like:
<a href="Test.htm#downbelow">Jump down!</a>
Hmmm, this is a more complex attribute. By default, the hostname in an absolute URL is constructed using a personalization expression. Something like:
http://<wm-hostname default="127.0.0.1" />/web/Home.htm
The intention here is to link to the host the visitor is actually browsing. Among others, this could be one of the frontends or the backend.
By using absoluteurl="true" and ignorePersonalization="true" together, the personalization expression is ignored and the "frontend_hostname" setting in /web/setup is used. This could mean the user switches hosts when following the link.
So there you have it... Interesting attributes that are useful to know but that are not revealed by the WebManager tag library "wm.tld".
My guess? I think the "wm.tld" is two thousand and eight while the attributes are two thousand and late. It's just that boom boom pow!
See you next time,
Patrick
P.S. Yes, I have requested an update of the documentation and the tag library. :-)
Patrick Atoon has gained nuff respect as one of the most experienced web architects in the GX Webmanager community or even the global hip hop community for that matter.
Read all Patricks blog entries
Other blog entries: