Monday, September 30, 2013

How to change page layout in Liferay

As a popular Content Management System (CMS), Liferay allowed users to personalize their own page layout.

As long as the users are given required permission, they are authorized to change their workspace layout.

By default, Administrator and Power User are roles given this permission.

Steps to personalize page layout in Liferay,
1. Login to Liferay with the Administrator role or Power User role.

2. navigate to the Page Layout dialog.
    Manage > Page Layout

3. Choose preferred page layout, then click Save.


Done!!

Saturday, September 28, 2013

Creating hyperlink with JSF components

normally JSF components accept an outcome from navigation case to generate hyperlink.
eg,
<h:link value="my link" outcome="MY_OUTCOME" />

<h:commandButton value="my button" action="MY_OUTCOME" />

<h:outputLink value="MY_OUTCOME">my link</h:outputLink />

But hyperlink generated with JSF outcome is only within the same application.
That's mean hyperlink generated with JSF components are unable to navigate to other sites. eg, google.com.

This problem could be resolved by <h:outputLink /> where the value attribute also accepts an URL.
eg.
<h:outputLink value="www.google.com">
    <h:outputText value="Google" />
    <f:param name="param1" value="value1" />
    <f:param name="param2" value="value2" />
</h:outputLink>

With the above codes, the <h:outputLink /> component able to generate hyperlink to www.google.com.

<f:param /> is optional, required only when passing parameters
eg.
www.google.com?param1=value1&param2=value2


Done!!

Wednesday, September 25, 2013

How to retrieve logged in user model in JSF2 Portlet

Retrieving logged in user is essential in every system, especially for logging purpose or authentication and authorization.

Steps to retrieve Liferay Logged in user in JSF portlet:
1. get the PortletRequest from JSF context
    PortletRequest portletRequest = (PortletRequest) FacesContext                                                                 .getCurrentInstance()
                                .getExternalContext().getRequest();

2. get the logged in user id
    String userId = portletRequest .getRemoteUser();

3. get the user model with Liferay API
    User user = UserServiceUtil.getUserById(Long.valueOf(userId));


Done!!

Sunday, September 22, 2013

Setting default user role, group, and site for a user in Liferay

The objective of this post is to show how to define role, group, site for a user especially when create a new user in Liferay.

meaning when creating a new user, what are the roles/groups/sites that are given to the user, unless intentionally changes it to other role/group/site.

To set the default user's role/group/site, follow the steps below:
1. Login as Liferay administrator.

2. Navigate to Default User Assiciations
    Go to > Control Panel > Portal > Portal Settings > Users > Default User Associations

3. Enter desired settings into the textbox.
    eg. if the Power User removes from the Roles textbox, that means new users created after this would have User role only, which is a limited authority role in Liferay.
    same applicable for Sites and User Groups, once defined in the textbox, it would be the default settings for newly created users, unless purposely changes it during create users.


Done!!

Thursday, September 19, 2013

Currency formatting with <f:convertNumber />

due to internationalization, the system should system the currency based on users' chosen currency or locale.
eg,
12345678.36 in US display as 12,345,678.36
12345678.36 in Danish (Denmark) display as 12.345.678,36
12345678.36 in German (Switzerland) display as 12'345'678.36

this could be easily handled by <f:convertNumber />, otherwise we might need to write a custom converter to handle this.

with <f:convertNumber />, we just need to pass in the system locale for the conversion.
<h:outputText id="balance" value="#{user.balance}">
    <f:convertNumber type="currency" locale="#{facesContext.viewRoot.locale}" />
</h:outputText>
with the above code, system will dynamically format the text value with system provided locale.

LinkWithin

Related Posts Plugin for WordPress, Blogger...