PortletFaces introduces several variables into the Expression Language (EL).
Table 6.3. PortletFaces EL Variables
| EL Variable | Description |
|---|---|
i18n
|
As an abbreviation for the word "internationalization", the i18n EL
variable enables page authors to declaratively specify message keys that hook into Liferay's
Language Utility.
Type:
|
liferay
|
Utility managed-bean that is designed to be kept in JSF request scope.
Its purpose is to introduce some Liferay-specific variables into the JSF
EL.
Type:
|
liferay.companyId
|
The Liferay companyId primary key value associated with the community/organization portal
page that the current portlet is placed upon.
Type:
|
liferay.documentLibraryURL
|
The absolute URL for the Liferay Document Library Struts action
path.
Type:
|
liferay.imageGalleryURL
|
The absolute URL for the Liferay Image Gallery Struts action
path.
Type:
|
liferay.imageURL
|
The absolute URL for the Liferay Image Servlet.
Type:
|
liferay.groupUser
|
The Liferay User that owns the Liferay community/organization portal
page that the current portlet is placed upon.
Type:
|
liferay.layout
|
The Liferay Layout associated with the community/organization portal
page that the current portlet is placed upon.
Type:
|
liferay.permissionChecker
|
The Liferay PermissionChecker associated with the current request and
Liferay User.
Type:
|
liferay.portalURL
|
The absolute URL for the portal.
Type:
|
liferay.portlet
|
the containing Liferay Portlet associated with the
PortletRequest.
Type:
|
liferay.portraitURL
|
Designed to be called from the EL by passing a Liferay User or
userId as an array index, returns the absolute URL to the user's
portrait.
Type:
|
liferay.service
|
Designed to be called from the EL by passing a Liferay service name String (bean id) as
an array index, returns the instance of the service class.
Type:
|
liferay.theme
|
The Liferay Theme associated with the Liferay
Layout.
Type:
|
liferay.themeDisplay
|
The Liferay ThemeDisplay associated with the
PortletRequest.
Type:
|
liferay.themeImageURL
|
Designed to be called from the EL by passing a relative path to a theme image as an array
index, returns the absolute URL to the theme image.
Type:
|
liferay.themeImagesURL
|
The absolute URL for the image path associated with the current Liferay
Theme.
Type:
|
liferay.user
|
The Liferay User associated with the
PortletRequest.
Type:
|
liferay.userHasPortletPermission
|
Designed to be called from the EL by passing an action-key as an array
index, returns a Boolean indicating whether or not the Liferay
User associated with the PortletRequest has permission to
execute the specified action-key on the current
portlet.
Type:
|
As an abbreviation for the word "internationalization", the i18n
EL variable enables page authors to declaratively specify message keys that are provided by one of the
following:
The Liferay Language Utility is typically accessed by portlet developers by calling static Java
methods found in the LanguageUtil class. The utility operates by reading the
locale-specific version of the portal's Language.properties file, which contains thousands of keys and
internationalized messages.
Portlet developers can extend the Liferay Language Utility by creating a file within the portlet WAR
named WEB-INF/liferay-hook.xml that points to locale-specific resource bundles
that are in the runtime classpath of the portlet.
Example 6.29. WEB-INF/liferay-hook.xml
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hook PUBLIC "-//Liferay//DTD Hook 5.2.0//EN" "http://www.liferay.com/dtd/liferay-hook_5_2_0.dtd"> <hook> <language-properties>Language_en_US.properties</language-properties> </hook>
Example 6.30. Contents of Language_en_US.properties
add-new-entry=Add New Entry save-entry=Save Entry
When using JBoss EL, page authors can take advantage of the i18n.replace() method
in order to substitute values into the text of the message.
Example 6.32. Usage of the i18n EL Variable with JBoss EL
<!--
Note: The US English translation of the x-has-x-friends key would look like the following:
x-has-x-friends={0} has {1} friends.
-->
<h:outputText value="#{i18n.replace('x-has-x-friends', liferay.groupUser.fullName, friendsModel.dataModel.rowCount)}" />
This is a utility managed-bean that is designed to be kept in request scope. Its purpose is to introduce some Liferay-specific variables into the JSF EL. The reason why this is implemented as a managed-bean (and not as an ELResolver) is because of the way ICEfaces 1.x handles Ajax requests. When an ICEfaces portlet is first rendered to the portal page, the ICEfaces portlet bridge participates in a normal manner with the portlet lifecycle. However, all user interactions that trigger an Ajax XMLHttpRequest (like partialSubmit) bypass the portlet lifecycle and go directly to the ICEfaces PersistentFacesServlet. While this has great benefits for speed, it introduces problems when ICEfaces portlets need to interact with Liferay resources that are scoped to the portlet lifecycle. For example, the Liferay ThemeDisplay object is available as a request attribute in the portlet lifecycle, but when the lifecycle is complete, Liferay's ServicePostAction will call the ThemeDisplay.recycle() method which invalidates all of the properties. If the portlet utilizing this managed bean is an ICEfaces portlet, then ICEfaces will place the instance of this class in its "extended" request scope, which will keep the Liferay-specific values in existence long after the portlet lifecycle has completed. If the portlet is a standard JSF portlet, then the JSF managed-bean facility will place the instance of this class in standard request scope. This introduces a small amount of overhead for standard JSF portlets, but is necessary in order to have PortetFaces supply a standard API for both ICEfaces portlets and JSF portlets.
The Liferay companyId primary key value associated with the community/organization portal page that the current portlet is placed upon.
Example 6.33. EL Usage of liferay.companyId
<h:outputText value="#{liferay.companyId} is the companyId associated with this set of Liferay Portal pages." />
The absolute URL for the Liferay Document Library Struts action path prefix. The most common use case is to append the /get_file suffix and some additional request parameters in order to provide a hyperlink to a document in the Liferay Document Library. See the Liferay struts-config.xml file for a complete list of available suffixes.
Example 6.34. EL Usage of liferay.documentLibraryURL
<h:dataTable id="documents" value="#{documentModelBean.dataModel}" var="dlFileEntry">
<h:column>
<f:facet name="head">
<h:outputText value="#{i18n['file-name']}" />
</f:facet>
<h:outputLink
target="_blank"
value="#{liferay.documentLibraryURL}/get_file?p_l_id=#{liferay.themeDisplay.plid}&folderId=#{dlFileEntry.folderId}&name=#{dlFileEntry.name}">
<h:outputText value="#{dlFileEntry.title}" />
</h:outputLink>
</h:column>
</h:dataTable>
The Liferay User that owns the Liferay community/organization portal page that the
current portlet is placed upon.
Example 6.35. EL Usage of liferay.groupUser
<h:outputText
value="The user named #{liferay.groupUser.fullName} owns this set of Liferay Portal pages." />
The absolute URL for the Liferay Image Gallery Struts action path prefix. See the Liferay struts-config.xml file for a complete list of available suffixes.
The absolute URL for the Liferay Image Servlet. Although this can be used to construct a URL that
points a Liferay user's portrait/photo, for performance reasons, it is better to use the portraitURL EL variable instead.
The Liferay Layout associated with the community/organization portal page that the
current portlet is placed upon.
Example 6.36. EL Usage of liferay.layout
<h:outputText
value="The name of this portal page is #{liferay.layout.name}" />
The Liferay PermissionChecker associated with the current request and Liferay
User.
Example 6.37. EL Usage of liferay.permissionChecker
<h:commandButton actionListener="#{backingBean.save}" rendered="#{liferay.permissionChecker.companyAdmin}" value="#{i18n['save']}" />
The containing Liferay Portlet associated with the
PortletRequest.
Example 6.38. EL Usage of liferay.portlet
<h:outputText
value="The name of this portlet is #{liferay.portlet.displayName}" />
Designed to be called from the EL by passing a Liferay User or
userId as an array index, returns the absolute URL to the user's portrait.
Example 6.39. EL Usage of liferay.portraitURL
<h:graphicImage value="#{liferay.portraitURL[liferay.group.user]}" />
Designed to be called from the EL by passing a Liferay service name String (bean id) as an array
index, returns the instance of the service class. Liferay manages instances of services using
Liferay-extended versions of the Spring XmlWebApplicationContext BeanFactory class named PortalApplicationContext
and PortletApplicationContext. The liferay.service extension to
the EL is meant to be used to resolve Liferay services so that they can be injected into JSF managed
beans via the managed-property feature inside of the portlet's
WEB-INF/faces-config.xml file.
Example 6.40. EL Usage of liferay.service (WEB-INF/faces-config.xml)
<managed-bean>
<managed-bean-name>modelManagedBean</managed-bean-name>
<managed-bean-class>mypackage.ModelManagedBean</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
<!-- Inject the service into the model managed bean. -->
<managed-property>
<property-name>myService</property-name>
<value>#{liferay.service['myservice.bean.id']}</value>
</managed-property>
</managed-bean>
The Liferay Theme associated with the Liferay Layout.
Example 6.41. EL Usage of liferay.theme
<h:outputText value="The name of the Liferay theme applied to this portal page is #{liferay.theme.name}" />
The Liferay ThemeDisplay associated with the PortletRequest.
Perhaps it is easier to think of the Liferay ThemeDisplay as a "display context" which provides access
to a wealth of information including the current Company, User, Layout, Theme, PermissionChecker, and
more.
Example 6.42. EL Usage of liferay.themeDisplay
<link href="#{liferay.themeDisplay.uRLSignIn}">#{i18n['sign-in']}</link>
Designed to be called from the EL by passing a relative path to a theme image as an array index, returns the absolute URL to the theme image.
Example 6.43. EL Usage of liferay.themeImageURL
<h:graphicImage value="#{liferay.themeImageURL['/common/delete.png']}" />
Returns the absolute URL for the image path associated with the current Liferay Theme. For example: http://localhost:8080/image/image_gallery.
Example 6.44. EL Usage of liferay.themeImagesURL
<h:graphicImage value="#{liferay.themeImagesURL}/common/delete.png" />
the Liferay User associated with the PortletRequest.
Example 6.45. EL Usage of liferay.user
<h:outputText value="#{i18n['welcome']}, #{liferay.user.firstName}" />
Designed to be called from the EL by passing an action-key as an array index, returns a
Boolean indicating whether or not the Liferay User associated with the
PortletRequest has permission to execute the specified action-key on the
current portlet. The action-key is typically defined in a Liferay
resource-action-mapping XML file that defines the
<portlet-resource/> and <model-resource/>
permissions associated with a Liferay portlet. Please refer to the
portal-impl/classes/resource-actions/messageboards.xml file in the Liferay Portal source code
distribution for an example of how to write a Liferay resource-action-mapping XML
file.
Example 6.46. EL Usage of liferay.userHasPortletPermission
<h:dataTable
rendered="#{liferay.userHasPortletPermission['VIEW']}"
value="#{modelManagedBean.users}"
var="user">
</h:dataTable>