Sign in

E-mail *, (xx@domain.com)
Password *

Register | Forgot password

Blogs

Recent blogs

RSS - Blogs
March 9, 2010
State of OSGi in the Java world
March 4, 2010
Reach more people with Google Translate
March 3, 2010
Get My Advice
February 26, 2010
What? Where!?!
February 11, 2010
Split it!

All Blogs...


wm:link secrets

June 18, 2009

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.


wm:link

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!


...Or is it?

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:

  • dbid
  • typeofpage
  • anchor
  • ignorePersonalization

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!



dbid and typeofpage

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>

anchor

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>

ignorePersonalization

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...

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. :-)


About the Author

Return to all blogs

 

Patrick Atoon

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:

February 26, 2010
What? Where!?!
September 3, 2009
Do the Right Thing
March 2, 2009
Server side represent! (Part 2)
February 4, 2009
Server side represent!
January 15, 2009
Making cache
December 9, 2008
Like A Version
August 19, 2008
Stop making sense
August 4, 2008
Namaste!
July 7, 2008
Japanese encore (日本のアンコール)
May 20, 2008
All amped up


Share:

del.icio.us
digg
Technorati
Slashdot
Reddit
YahooMyWeb
NewsVine
ekudos
© 2010 GX creative online development B.V.

Disclaimer

This website (GXdeveloperweb.com) may discuss or contain opinions, (sample) coding, software or other information that does not include GX official interfaces, instructions or guidelines and therefore is not supported by GX. Changes made based on this information are not supported.  GX will not be held liable for any damages caused by using or misusing the information, software, instructions, code or methods suggested on this website, and anyone using these methods does so at his/her own risk. GX offers no guarantees and assumes no responsibility or liability of any type with respect to the content of this website, including any liability resulting from incompatibility between the content of this website and the materials and services offered by GX. By using this website you will not hold, or seek to hold, GX responsible or liable with respect to the content of this website.