Tuesday, October 28, 2014

Loop index in Apache Velocity

To get the loop index in Velocity template,
we need to initiate a temporary index variable, and increase the variable count by 1 after every occurrence in the loop.

#set( $count = 1 )
<table>
#foreach( $customer in $customers )
    <tr>
        <td>$count</td>
        <td>$customer.name</td>
        <td>$customer.age</td>
    </tr>
#set( $count = $count + 1 )
#end
</table>

the idea is what we have in the for loop.
int count = 1;
for(Customer c : customerList) {
    print(...);
    count++;
}


Done!!

How to disable row selection in PrimeFaces datatable

This is not a official/proper way to disable the row selection in <p:dataTable />
But a workaround since there is no way to disable the row selection at the moment.

assuming we have the following dataTable.
<p:dataTable
    value="#{myBean.resultList}"
    selection="#{myBean.selection}"
    var="var"
    ..... />

    <p:column selectionMode="multiple" />
    <p:column .... />

</p:dataTable>

To disable row selection in the above <p:dataTable />
we need to add <p:ajax /> into the <p:dataTable />

Thursday, October 23, 2014

How to check system configured properties in Liferay

There are a lot of  properties/attributes configured in Liferay.
All these configured System Properties and Portal Properties could be accessed through Server Administration.

1. Login as Liferay Administrator

2. Liferay 6.1.x
    Go to > Control Panel > Server > Server Administration > Properties

Wednesday, October 22, 2014

How to set max date and min date in <p:calendar />

The maxdate and mindate attribute is extremely useful for setting available date range for user selection.

e.g.
-Expiry date of an item should not be less than today.
-Date of birth should not be future date.

So how to set maxdate and mindate in PrimeFaces calendar component?

1. create the java.util.date object in backingBean
private Date currentDate = new Date();

public Date getCurrentDate() {

    return currentDate;
}

2. set the java.util.date object as mindate or maxdate
<p:calendar value="#{bean.expiryDate}" mindate="#{bean.currentDate}" />
 

<p:calendar value="#{bean.birthDate}" maxdate="#{bean.currentDate}" />


Done!!

Tuesday, October 21, 2014

How to display dynamic PDF document with <p:media /> component

From the PrimeFaces showcase, the media component used to display PDF document
But the showcase uses a static PDF document.

In real life, we might want to display different PDF documents by different use cases,
or a runtime generated PDF document.

To achieve the above purpose, we need to use the value attribute in <p:media /> component by passing in a StreamedContent from backingBean.

1. BackingBean method that return StreamedContent.
public StreamedContent getPdfDocument() {  

     // logic to generate the PDF  

    return new DefaultStreamedContent(pdfInByteArrayInputStream, "application/pdf");
}


2. display the PDF content with <p:media /> component.

<p:media value="#{myBean.pdfDocument}" width="100%" height="500px" player="pdf" />


Done!!

LinkWithin

Related Posts Plugin for WordPress, Blogger...