Monday, January 27, 2014

Loading Velocity template in JSF

When loading Velocity template with the default setting.
The following exception might be hit
org.apache.velocity.exception.ResourceNotFoundException: Unable to find resource

Even I used the Class Resource Loader, still hitting the same exception.

The exception solved when used File Resource Loader together with the system Real Path.
String myTemplatePath = FacesContext.getCurrentInstance().getExternalContext().getRealPath("/WEB-INF/mytemplatepath");

Properties p = new Properties();
p.setProperty( "file.resource.loader.path", myTemplatePath);

Template template = Velocity.getTemplate( "mytemplate1.vm" );

p/s: assuming all .vm files are kept under <webapp>/WEB-INF/mytemplatepath folder.


Wednesday, January 22, 2014

How to support multiple languages for Liferay Page

By default, Liferay supporting English with locale en_US.
In some cases, we might want our Portal to support multiple languages in order to support visitors from other countries.

Thus, the objective of this post is to show how to support multiple languages in Liferay Pages.

1. login in as Administrator into Liferay.

2. open "Manage Page" dialog by clicking Manage > Page

Sunday, January 19, 2014

Liferay Portlet Title Internationalization

By default, the Portlet title is in English with locale en_US.
To support internationalization, we can provide the Portlet title in different languages with the following steps.

1. Login to Liferay as Administrator.

2. on the target Portlet, click on Options > Look and Feel

Thursday, January 16, 2014

How to generate PDF in Liferay PrimeFaces Portlet with iText

The objective of this post is to show how to generate PDF with iText in Liferay PrimeFaces Portlet.
The idea is to generate the PDF stream with iText and then download it with <p:fileDownload />.

Liferay 6.1.1
PrimeFaces 3.5
iText 2.0.8 and core-renderer-R8

1. Create the content in PDF stream with iText
    public byte[] getPdfStream() {
      byte[] pdf = null;
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      String html = "<!DOCTYPE HTML><html><body>Generate PDF Test</body></html>";
      try {
              ITextRenderer itextRenderer = new ITextRenderer();
              pdf = baos.toByteArray();
      catch (Exception e) {

2. Prepare the StreamedContent as <p:fileDownload /> value
    public StreamedContent getPdfFile() throws Exception {
     PortletResponse portletResponse = (PortletResponse) FacesContext
     HttpServletResponse res = PortalUtil
     res.setHeader("Content-Disposition", "attachment; filename=\""
          + "test-kian.pdf" + "\"");//
     res.setHeader("Content-Transfer-Encoding", "binary");

  OutputStream out = res.getOutputStream();

     return null;

3. Download the PDF with <p:fileDownload /> in xhtml
<p:commandButton value="download PDF" ajax="false">
    <p:fileDownload value="#{myBean.pdfFile}" />

4. To generate styled PDF, please refer How to generate styled PDF in Liferay PrimeFaces Portlet with iText


Monday, January 13, 2014

PrimeFaces DataTable Selection Event

Following is the list of available events for row selection when using <p:dataTable />

No. Event Purpose/Usage
1 rowSelect Select a row by clicking on the row
2 rowUnselect Unselect a row by clicking on the row
3 rowSelectCheckbox Select a row by checking the selection checkbox
4 rowUnselectCheckbox Unselect a row by unchecking the selection checkbox
5 toggleSelect Select/Unselect all rows by clicking on the header checkbox
6 rowDblselect Select/Unselect a row when D-click


Friday, January 10, 2014

Getting Liferay Signed in user in XHTML

Check the session is signed in in XHTML

Get the signed in user in XHTML

Get the signed in user's properties in XHTML


Tuesday, January 7, 2014

How to configure memory for Oracle SQL Developer

To increase maximum memory to use

1. Navigate to <SQL_Developer_Installation_Dir>/sqldeveloper/bin
2. Open sqldeveloper.bat with notepad
3. edit the Xmx vm option

To increase maximum Perm size to use

1. Navigate to <SQL_Developer_Installation_Dir>/sqldeveloper/bin
2. Open sqldeveloper.conf with notepad
3. edit the MaxPermSize vm option


Saturday, January 4, 2014

How to define Permission for a role in Liferay

1. Login as Administrator

2. Go to > Control Panel > Portal > Roles

3. Click on a Role, eg. My Role

Wednesday, January 1, 2014

EclipseLink Static weaving with Ant

<?xml version="1.0"?>
<!DOCTYPE project>

<project name="staticWeaving" default="weaving">  

<target name="define.task"
description="New task definition for EclipseLink static weaving" >
<classpath refid="project.class.path" />

<target name="weaving" description="perform weaving." depends="define.task">
<classpath refid="project.class.path" />

<path id="project.class.path">
   <pathelement path="eclipselink.jar/"/>
  <pathelement path="hibernate-jpa-2.0-api-1.0.1.Final.jar"/>



Related Posts Plugin for WordPress, Blogger...