Sunday, March 31, 2013

How to format java source nicely with Eclipse

This is an Eclipse built-in feature to help us format java source nicely.
During development, the source code could be written in anyway, eg, code in a single line too long, thus need to scroll left and right to read.
This is very important, so that our source codes are easy to read and maintain at the future.

To resolve this problem, we can simply invoke this function in Eclipse to format it nicely and easily.

1. format a source file.
    a) R-click on the target source file > source > format.

2. format the entire java project.
    a) R-click on the target project > source > format.


Saturday, March 30, 2013

Code review with Eclipse PMD plugin

PMD is an Eclipse plugin that provides automates code review.
With PMD installed, code review can be done in short time, and make sure codes are reviewed under defined rules and standard.

1. Install PMD.
2. R-click on any project > PMD > Check Code with PMD

Wednesday, March 27, 2013

Workaround for p:contextMenu in dataTable

There is a demo in Primefaces showcase, how p:dataTable integrates with p:contextMenu.
But this integration ONLY allowed p:contextMenu to work in row level.

If we are invoking the contextMenu from table cell, or a button in table.
It is impossible with the current p:contextMenu implementation.

There is an alternative way with p:menuButton.
p:menuButton demo
1. Styleclass - change the down arrow icon.
2. Styleclass - hide button border and background colour.
3. remove the button text (value)
4. use the custom styleclass in p:menuButton

Sunday, March 24, 2013

How to add/remove row in datatable

JSF Datatable is a data driven component, total number of table row depends on number of records in datamodel that is binding to the datatable.

Thus, to add/remove a row in datatable is actually an action to add/remove record in the datamodel.

1. Prepare the value object / entity.
Value Object or Entity for datatable

Thursday, March 21, 2013

How to change the number of workspace history in Eclipse

Sometimes, we are currently working in multiple workspaces, or we want to keep some old workspaces in the Eclipse workspace list.
By default, Eclipse can only keeps track up 5 workspaces.
So there could be problem when we want to open previous workspaces.

workspace1 disappear

To resolve this problem, we can increase the number of workspaces history in Eclipse.

Tuesday, March 19, 2013

How to insert spaces instead of tab in Eclipse

It's always a good practice to insert 4 spaces instead of tab when code indentation.
Eclipse can automates this process. Thus when we press "Tab" key, it simply insert 4 spaces into code.

1. Start Eclipse
2. Windows > Preferences > General > Editors > Text Editors

Monday, March 18, 2013

How to order child collection in JPA

Assume there are 2 entities, Parent and Child
In many cases, children collection are directly retrieve from parent entity without writing additional query.
But there is a problem to retrieve children collection directly from parent entity -- the children collection are in an unsorted manner.
This problem could be solved by adding the @OrderBy annotation.

public class Parent {

    private Set<Child> children;

    // More attributes

public class Child {
    private Parent parent;    
        //More attributes

Import/Export MySQL database with SQLyog

This post shows how to export a MySQL database with SQLyog then import it back to another MySQL server.

Export MySQL Database
1. Start SQLyog
2. Tools > Backup Database As SQL Dump ...
sqlyog - SQL Dump

Friday, March 15, 2013

How to copy Oracle database with Oracle SQL Developer

This is another option to back up / clone an existing Oracle database to another database.
and the advantage of this option is, Administrator right is not required for the user who performing the copy option.

1. Start Oracle SQL Developer
2. Tools > Database Copy... > New Copy Wizard
Oracle SQL Developer - copy wizard

import/export of oracle database

The purpose of this post is to show the important steps, parameters and sample when importing / exporting an Oracle database.

Required parameters:
- USERNAME - database user with administrator right
- PASSWORD - password for the database user
- SERVICE - database schema to import/export
- FILENAME - unique file name for dump file
- TABLE_NAME - database tables' name to export

1. Export database:


2. Export selected tables:


3. Import database:


4. Import database (remap existing schema to a new schema):


another way to import the existing Oracle database to other Oracle database server is to copy the database with Oracle SQL Developer


Wednesday, March 13, 2013

Easy way to add AJAX action to HTML element with Richfaces and Primefaces

In some cases, HTML elements still need to be used in JSF due to certain limitations.
But HTML component is lack of AJAX support.
Thus, the objective of this post is to show how to add AJAX event to a HTML element without writing any javascript.

this can be achieved with <a4j:jsFunction /> in Richfaces and <p:remoteCommand /> in Primefaces.

1. Define the AJAX action to be invoked in xhtml.
(a) Richfaces
        render="[component id to render]">

(b) Primefaces
        update="[component id to update]">

2. invoke the AJAX action in HTML element.
<input type="checkbox" onclick="updateIndexWhenOnclick();" />


Monday, March 11, 2013

Primefaces fileDownload in Liferay

When I tried to use <p:fileDownload /> in Liferay, with the simplest code shown in the demo site.
primefaces fileDownload code snippet
But the file is failed to download.
To resolve this issue, I ended up with the following steps.
Notes: issue reported in Liferay -

Public StreamData getFile() {
  // 1. initialize the fileInputStream
  // 2. get Liferay's ServletResponse
  // 3. write the file into the outputStream
  // 4. return null to this method

Thursday, March 7, 2013

How to integrate OpenFire with OpenDJ(LDAP)

The objective of this post is to show the steps on integrating OpenFire and OpenDJ

OpenAM 3.7.1
OpenDJ 2.5.0

1. OpenDJ is installed

1. During OpenFire configuration, in Profile Settings, choose Directory Server (LDAP), Continue.
2. in Connection Settings, fill in the OpenDJ configurations.


Related Posts Plugin for WordPress, Blogger...