Profile

Recent Bloggers

Juan Fernández Posts: 2
Stars: 4
Date: 2/9/10
Aaron Delani Posts: 3
Stars: 8
Date: 2/8/10
James Min Posts: 23
Stars: 41
Date: 2/8/10
Jonas Yuan Posts: 12
Stars: 30
Date: 2/8/10
Ronald Sarayudej Posts: 83
Stars: 226
Date: 2/8/10
Julio Camarero Posts: 6
Stars: 18
Date: 2/8/10
David Truong Posts: 9
Stars: 29
Date: 2/3/10
Neil Griffin Posts: 22
Stars: 57
Date: 2/3/10
Paul Hinz Posts: 1
Stars: 7
Date: 2/3/10
Bryan Cheung Posts: 19
Stars: 84
Date: 1/27/10

Blogs

Blogs »
Calling Java (tools|services) from XSL Journal Templates

Recently a coleague asked if it was possible to call java from XSL.

It is possible, and here is the example I provided.

<?xml version="1.0"?>
<xsl:stylesheet 
	version="1.0" 
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
	xmlns:getterUtil="xalan://com.liferay.portal.kernel.util.GetterUtil"
	xmlns:java="http://xml.apache.org/xalan/java"
	xmlns:userLocalServiceUtil="xalan://com.liferay.portal.service.UserLocalServiceUtil"
	exclude-result-prefixes="java" 
	extension-element-prefixes="getterUtil userLocalServiceUtil">

	<xsl:output method="html" omit-xml-declaration="yes"/>
		
	<xsl:template match="/">

		<xsl:variable name="remote-user" select="/root/request/remote-user" />
		
		<xsl:text>Remote User: </xsl:text>
		<xsl:value-of select="$remote-user" />
		
		<div class="separator"><!--//--></div>
		
		<xsl:choose>
			<xsl:when test="$remote-user != ''">
				<xsl:variable name="user" select="userLocalServiceUtil:getUserById(getterUtil:getLong($remote-user))" />
	
				<xsl:text>Hello </xsl:text>
				<xsl:value-of select="java:getFullName($user)" />
				<xsl:text>!</xsl:text>
			</xsl:when>
			<xsl:otherwise>
				<xsl:text>Hello! Please log in.</xsl:text>
			</xsl:otherwise>
		</xsl:choose>

	</xsl:template>
</xsl:stylesheet>
VM (VTL) is great and all, but when it comes to dealing with XML data, you simply can't beat the power of XSL. Add to that the power of inline java and you can do some nifty stuff.
Comments Flat View

Ray,

I have heard you mention a feature in the Journal that lets you submit a form on itself . Is the technique you mentioned above a similar way to achieve the form submitting in a Journal? If not, can you pls post an example code on how to do it.

Thx again for sharing this useful information.

Posted on 9/12/08 12:49 PM.

Top Top
Hi Ray!

I was trying to get Calendar Entries with this wonderful feature, but I can't get it work...

I was able to get a specific Event using the code below, but not the latest / upcoming events.
1
2        <xsl:variable name="result" select="serviceUtil:getEvent(9999)" />


I was trying to use the CalEventLocalServiceUtil.getEvents(groupId, java.util.Calendar) and couldn't get it work because I couldn't get the groupId nor a Calendar instance.

I also tried CalEventLocalServiceUtil.getCalEvents(start, end), but I couldn't make it work =(

Could you please give me a hand on this?

Thanks for your fantastic work!

Mariano.

Posted on 9/23/08 10:43 AM.

Top Top
See http://www.liferay.com/web/rauge/blog/-/blogs/calling-liferay-services-from-xsl-journal-templates

HTH!

Posted on 9/23/08 12:33 PM in reply to Mariano Cifre.

Top Top
You are THE MAN! :-)

Thanks Ray! As always, you are very helpful!

Cheers,
Mariano.

Posted on 9/23/08 3:00 PM in reply to Ray Augé.

Top Top