Wednesday, October 30, 2013

Body onload with PrimeFaces autoRun

To perform an action during page load, the normal practice is to invoke a javascript with the onload attribute in HTML body.

function load() {
alert("Page is loaded");
<body onload="load()">
<h1>Hello World!</h1>

With PrimeFaces <p:remoteCommand /> component, backingBean action could be called directly during page load.
by turning on the autoRun attribute to true only.
<p:remoteCommand name="testAutoRun"
    autoRun="true" />

The benefits with <p:remoteCommand /> are:
1. easy to use
2. No hassles to write any javascript
3. other pages are not affected (if facelets template is used)


Sunday, October 27, 2013

How to get client id in Liferay PrimeFaces portlet

There is a convenient function in PrimeFaces to get client id of a component.
That is #{p:component('compId')}
The above function returns a full client id, eg. form:compId

But the full client id returned in Liferay portlet is not usable.
because Liferay portal is appending an unique id in front of form to make the client id unique.
eg. A8838:form:compId

Thus, the returned id is not a valid id in PrimeFaces or JSF context.

 JSTL functions could be used to solve this issue.


with the above syntax, the returned id will igore the text before the first ":"
Thus, returned id would be form:compId


Thursday, October 24, 2013

Looping in JSF dataTable

To build a dataTable with dynamic columns in RichFaces,
we may use <c:foreach /> or <rich:columns /> in <rich:dataTable />
<rich:dataTable var="var" value="#{myBean.list}">
    <c:foreach var="column" value="#{myBean.columns}">
            <f:facet name="header">
                <h:outputLabel value="#{}" />
            <h:outputLabel value="#{var[column.value]}" />

But the same is not applicable in <p:dataTable />
because <ui:repeat /> and <c:foreach /> is not working in <p:dataTable />
Thus, the only solution to achieve dynamic column in <p:dataTable /> is to use <p:columns />
<p:dataTable var="var" value="#{myBean.list}">
    <p:columns var="colomn" value="#{myBean.columns}">
        <f:facet name="header">
            <h:outputLabel value="#{}" />
        <h:outputLabel value="#{var[column.value]}" />

With <c:foreach /> or <ui:repeat />, more flexibilities could be achieved.
Since they are not working in <p:dataTable />, the only way to achieve looping is <p:columns /> with less flexibilities.


Monday, October 21, 2013

Accessing bean's property dynamically like a map

Assuming we have the following class
public class MyBean {
    private String property1;
    private String property2;

    // getter and setting for property1, property2, ...

Normally we are accessing the properties in a bean from xhtml like syntax below.

But, recently found that we can actually accessing the properties of a bean like accessing a map.


in normally circumstances, it is nothing special from the traditional way.
But it is relatively useful if we want to dynamically access the properties in a bean.


Friday, October 18, 2013

How to find deployed portlet id in Liferay

To find the targeted portlet id in Liferay, follow the below steps:

1. Login to Liferay portal as Administrator
    For user without Administrator rights, Portlet id could be retrieve from browser URL.

2. Navigate to Portlet Plugins
Go to > Control Panel > Portal > Plugins Configuration > Portlet Plugins

3. Click on the targeted portlet from the list, the portlet id will be shown in the details page.


Tuesday, October 15, 2013

How to add user(s) in JBoss AS7

To add user(s) to JBoss AS7.
1. navigate to <JBoss_installation_directory>/bin

2. d-click add-user.bat in window or execute in Linux

3. Choose user type, either a or b

Saturday, October 12, 2013

Hacking the JBoss JNDI Datasource configuration

The previous post shows how to create the JNDI datasource connection in JBoss AS7.
There is also a quick way to hack the JBoss JNDI datasource configuration.
This allowed us to modify / create / delete the datasource connection without login to JBoss AS7 admin console.

1. open standalone.xml in <JBoss installation directory>/standalone/configuration.

2. search for <datasources, <datasource /> between <datasources> ... </datasources> are the JNDI datasource connections available in JBoss AS7.

3. modify <datasource />
    - changing the jdbc url, username, password of the existing datasource connection.
    - create another new JNDI datasource connection
    - delete the <datasource /> that is no longer in used.


Wednesday, October 9, 2013

How to create JNDI datasource in JBoss AS7

This post shows how to create JNDI for datasource connection in JBoss AS7.
There is another post to show how to create JNDI datasource in Oracle Weblogic


1. login as management user in JBoss admin console

Sunday, October 6, 2013

How to deploy jdbc driver as a module in JBoss AS7

When multiple applications are using the same jdbc driver in an JBoss AS7, it is good to deploy the jdbc driver as a module instead of deploying the jdbc driver in every applications.

or we need to create JNDI datasource connection in JBoss AS7, then it is a must to deploy the jdbc driver into JBoss AS7, else JBoss AS7 is unable to create database connection to the target DB.

1. create folder in <JBoss_AS7_installation_folder>/modules
    eg, oracle

Thursday, October 3, 2013

How to create JNDI datasource in Oracle Weblogic

This post shows how to create a JNDI datasource in Oracle Weblogic.
From security perspective, JNDI datasource is good to hide the database connection details in the application server console.
Thus only Administrator can view and change the database connection settings.

1. navigate to weblogic console (normal http://localhost:7001/console), and login as weblogic admin to Weblogic Administration Console


Related Posts Plugin for WordPress, Blogger...