Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Tobias Hofmann
XSLT and Java Object
December 10, 2008 12:04 PM
Answer

Tobias Hofmann

Rank: Junior Member

Posts: 82

Join Date: June 20, 2007

Recent Posts

Hi,

I want to get the user's name/id and password in a XSLT template.
Like:
<xsl:variable name="username" select="java:<Java Function>()" />
<xsl:variable name="password" select="java:<Java Function>($username)" />

How can I achive this? What is the right Java object to call?

Tobias
Victor Zorin
RE: XSLT and Java Object
December 10, 2008 2:55 PM
Answer

Victor Zorin

Rank: Liferay Legend

Posts: 1176

Join Date: April 14, 2008

Recent Posts

Where do you execute this XSLT transformation?
You can make suitable Java Object using com.liferay.portal.util.PortalUtil, but you need
to have access to userId or portlet request.
Tobias Hofmann
RE: XSLT and Java Object
December 11, 2008 4:54 AM
Answer

Tobias Hofmann

Rank: Junior Member

Posts: 82

Join Date: June 20, 2007

Recent Posts

Hi,

the XSLT transformation will be executed as a Liferay CMS template/article.

How can I get the userId from XSLT? Are there some predefined variables like under VM? I saw on a blog a [ here ] the usage of
1<xsl:variable name="remote-user" select="/root/request/remote-user" />

Exist the same funcionality to get the userId? like: select="/root/request/userId?

br,
Tobias
Victor Zorin
RE: XSLT and Java Object
December 15, 2008 9:38 PM
Answer

Victor Zorin

Rank: Liferay Legend

Posts: 1176

Join Date: April 14, 2008

Recent Posts

I see, by default the following xpath variables are available under /root/request:
* container-namespace
* content-type
* server-name
* server-port
* auth-type
* locale
* window-state, etc, etc
For a full list look into com.liferay.util.portlet.PortletRequestUtil.

To get to user-related parameters, use /root/request/remote-user as userId.
Then find any Utility class that has static method which takes (long userId) as
parameter and returns requested value, eg. full name.

I'll have a look what is available and will come back to you with options.
Victor Zorin
RE: XSLT and Java Object
December 17, 2008 3:36 PM
Answer

Victor Zorin

Rank: Liferay Legend

Posts: 1176

Join Date: April 14, 2008

Recent Posts

This is an example of displaying user details using XSL article.
User password is displayed in encrypted form if it is encrypted in the database.

XSLT template code:
 1<?xml version="1.0"?>
 2
 3<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
 4  xmlns:java="http://xml.apache.org/xalan/java"
 5  xmlns:getterUtil="xalan://com.liferay.portal.kernel.util.GetterUtil"
 6  xmlns:userLocalServiceUtil="xalan://com.liferay.portal.service.UserLocalServiceUtil">
 7<xsl:output method="html" omit-xml-declaration="yes"/>
 8<xsl:variable name="remote-user" select="/root/request/remote-user" />
 9<xsl:template match="/">
10  <xsl:choose>
11    <xsl:when test="$remote-user != ''">
12      <xsl:variable name="user" select="userLocalServiceUtil:getUserById($remote-user)" />
13      User ID : <xsl:value-of select="$remote-user" />. <br/>
14      User Name : <xsl:value-of select="java:getFullName($user)" />. <br/>
15      User Screen Name : <xsl:value-of select="java:getScreenName($user)" />. <br/>
16      User Email: <xsl:value-of select="java:getEmailAddress($user)" />. <br/>
17      User Password: <xsl:value-of select="java:getPassword($user)" />. <br/>
18    </xsl:when>
19  <xsl:otherwise>
20    <xsl:text>User is not logged in</xsl:text>
21  </xsl:otherwise>
22</xsl:choose>
23
24</xsl:template>
25</xsl:stylesheet>


Structure:
1<root>
2  <dynamic-element name='mytext' type='text'></dynamic-element>
3</root>
Tobias Hofmann
RE: XSLT and Java Object
December 19, 2008 5:16 AM
Answer

Tobias Hofmann

Rank: Junior Member

Posts: 82

Join Date: June 20, 2007

Recent Posts

Thank you. This is a REALLY helpful answer.

Tobais