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.

Monday, September 16, 2013

How to configure Mail server settings in Liferay

To configure Mail server settings in Liferay,
first must login with administrator role. and then perform the following steps.

1. Navigate to Mail server settings page.
    Go to > Control Panel > Server > Server Administration > Mail

2. Enter valid incoming (POP) and outgoing (SMTP) mail server settings

3. Save


Done!!

Friday, September 13, 2013

Alignment issue on p:selectOneMenu

When <p:selectOneMenu /> aligns with other components.
It is align slightly upper than other components.

To resolve this issue.
simply put each component into each individual <td /> or a panelGrid to wrap the components.
<h:panelGrid columns="3">
  <p:inputText></p:inputText>
  <p:commandButton value="test"></p:commandButton>
  <p:selectOneMenu>
    <f:selectItem itemLabel="select" itemValue=""/>
  </p:selectOneMenu>
</h:panelGrid>

output:


Done!!

Tuesday, September 10, 2013

How to delete user(s) in Liferay

To delete user(s) in Liferay, we must login to Liferay Portal with Administrator role.

1. Navigate to Users and Organizations
    Go to > Control Panel > Portal > User and Organization

2. Choose user(s) to deactivate

3. Search all inactive user(s).
    a) Click the Search All Users link
    b) Choose Inactive in the Status dropdown
    c) Click Search

4. Choose user(s) to delete from the inactive list.


Done!!

Saturday, September 7, 2013

How to pass parameters with p:remoteCommand

In some cases, we might want to invoke an server side action via java script.
This can be done by <p:remoteCommand />.
with <p:remoteCommand />, we could assign a name to the remoteCommand component, then invoke the remoteCommand's action with the given name
<p:remoteCommand name="rcTest"
    action="#{myBean.someAction}"
    update="any_component_id" />

<p:commandButton value="remote command test" onclick="rcTest();" />

In Addition, we might want to pass in some parameters to our server side action with the following syntax.
<p:commandButton value="remote command test" 
    onclick="rcTest([{name:'myName1',value:'myValue1'},{name:'myName2',value:myValue2}]);" />

Tuesday, September 3, 2013

How to create side menu layout with p:menu

The objective of this post is to create side menu layout as below.

1. create a side menu template
<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
 xmlns:h="http://java.sun.com/jsf/html"
 xmlns:ui="http://java.sun.com/jsf/facelets"> 

<h:head />
<h:body>
 <h:form>
        <table>
            <tr>
                <td><ui:insert name="sidemenu" /></td>
                <td><ui:insert name="content" /></td>
            </tr>
        </table>
  </h:form>
</h:body>
</html>

Sunday, September 1, 2013

How to create side menu layout with p:tabView

The objective of this post is to develop below layout with <p:tabView /> component.

With the tabView component, the above layout could be easily developed with the orientation attribute.
<p:tabView orientation="left">
    <p:tab title="tab1">
        <h:outputLabel value="this is tab 1" />
    </p:tab>
    <p:tab title="tab2">
        <h:outputLabel value="this is tab 2" />
    </p:tab>
</p:tabView>

output:

related topic.
How to create side menu layout with p:menu

Done!!

LinkWithin

Related Posts Plugin for WordPress, Blogger...