Thursday, May 31, 2012

Quick tip: Get hostname with EL

Here's a quick little tip, something I hadn't realized before and wanted to share.

Normally when I need to get the host name used in the current request I would do something like:
#{javascript:context.getUrl().getHost()}
It's a Javascript call, which is always slower than pure Java or Expression Language (EL). Where possible I try to use EL instead of Javascript.

So, can you achieve the same result with EL? Yes, and it's actually pretty straightforward. Just drop the "get" and "()" and fix the case:
#{context.url.host}
There's another example on the XPages Wiki.

Happy hacking!

No comments:

Post a Comment