Saturday, December 31, 2016

Eclipselink Cache Coordination with JBoss and JMS

  1. Creating JPA project and generating entities.
  2. Configuring persistence properties and JPA project
  3. Testing the JPA project
  4. Update database when entity changed.
  5. Setting up load balance database connection.
  6. Setting Cache Coordination in Eclipselink

Cache Coordination enables EclipseLink to synchronize data changes in a distributed environment. for more information about cache coordination in EclipseLink, click here.

Following are the steps to enable Cache Coordination in JBoss AS7 / JBoss EAP6.
1. create JMS topic

2. creaet JMS connection factory

3. add the cache coordination properties into persistence.xml
<property name="eclipselink.cache.coordination.protocol" value="jms" />

<property name="eclipselink.cache.coordination.jms.topic" value="jms/EclipseLinkTopic" />

<property name="eclipselink.cache.coordination.jms.factory" value="jms/EclipseLinkTopicConnectionFactory" />

<property name="eclipselink.cache.coordination.jms.reuse-topic-publisher" value="true" />

<property name="" value="remote://HOST:PORT" />

4. in eclipseLink module.xml, add the following into <dependencies />
<module name="javax.jms.api"/>

5. in hornetq module.xml, add the following into <dependencies />
<module name="org.eclipse.persistence"/>


Wednesday, November 30, 2016

Putting and getting data to/from infinispan

Example shown below is applicable and tested working in JBoss EAP 6.x and JBoss AS 7.x

1. Inject the cache container with @resouce annotation.
    a) name, inject with the container name
    b) lookup, inject with the jndi name configured in the cache container.

code below is presented with method (a)
@Resource(name = "java:jboss/infinispan/container/CACHE-CONTAINER-NAME-IN-STANDALONE.XML")
private CacheContainer container;

make sure the cache container name exist in standalone.xml 
else there will be NullPointerException when getting the cache from the cache container.

Monday, October 3, 2016

Add and remove JMS queue in JBoss admin console

1. navigate to JBoss Console login page and login as admin

2. navigate JMS Messaging Provider
    Profile > Messaging > Messaging Provider, click View

3. Click JMS Destination

4. under Queues tab, click add

5. fill in the form, click Save

6. Review the Queue summary


Wednesday, September 21, 2016

How to activate / inactivate Portlet in LIferay

1. Login as Liferay Administrator

2. Navigate to Plugins Configuration
    Control Panel > Apps > Plugins Configuration

3. Click on 1 of the plugin from the list, eg. Documents and Media

4. untick the "Active" checkbox.

5. Save.

With these steps, the Documents and Media portlet/plugin has been deactivated.


Tuesday, September 20, 2016

How to get size of a java collection in xhtml

Basically there are 2 ways to get the size of a collection / list in xhtml.
1. jstl function
#{ fn:length(myList) }
2. call the size() function directly
#{ myList.size() }


Tuesday, August 2, 2016

PrimeFaces fileUpload javascript properties


upload content

number of uploaded files
var files = fileuplaod_wgt.uploadContent.find('.files .template-upload');

invalid files


Monday, June 27, 2016

How to disable Choose button in PrimeFaces fileupload component

The javascript function is to disable "Choose" button in <p:fileUpload /> component a file has been uploaded.
It is applicable to PrimeFaces 3.5

function below will find the Choose button from the passed in widgetVar when the file component onchange,
if the number of uploaded files more than 1,
disable the Choose button.

<script type="text/javascript">

    function onchangeDisableChooseBtn(upload_widget_var) {
        if(upload_widget_var.buttonBar.find('input[type=file]').get(0).type == 'file') {
            upload_widget_var.buttonBar.find('input[type=file]').change(function() {
                var files = upload_widget_var.uploadContent.find('.files tr');
                if (files.length >= 1) {



Wednesday, June 22, 2016

How to hide icons in PrimeFaces fileUpload component.

PrimeFaces version: 3.5

to hide icon in choose button

  .fileupload-buttonbar .fileinput-button .ui-icon-plusthick{
         display: none !important;

to hide icon in upload button

 .fileupload-buttonbar .start .ui-icon-arrowreturnthick-1-n{
         display: none !important;

to hide icon in cancel button

 .fileupload-buttonbar .cancel .ui-icon-cancel{
         display: none !important;


Tuesday, June 21, 2016

Blinking Text effect

<span id="elementIdToBlink">    
   any text to blink.

    // Self-executing recursive animation
    (function pulse(){



Monday, June 20, 2016

Encryption/Decryption with Java

Following are the steps to encrypt/decrypt with Java
1. determine the encryption key
2. get the keyspec from the encryption key  
3. instantiate the secretkeyfactory
4. generate the secretkey from the keyfactory
5. instantiate the cipher
6. encrypt/decrypt the string into byte array
7. encode to base 64
8. return the encrypted/decrypted string

Sample Code

    public static final String key = "kianworknotes";

Monday, February 22, 2016

How to override JSF library in JBoss

In normal scenario, JBoss is bundled with JSF libraries.
But it might be older and stable version of JSF.

 Due to more features enhancement, bug fixes. We might want to use a more latest version of JSF for our application.
1 way is to upgrade the entire JBoss AS, but this is risky to all the existing applications that are running on the same JBoss AS.

to avoid unexpected issues to existing applications. we can proceed to upgrade the JSF libraries on the new JSF applications only.
We just need to bundled the latest JSF libraris in the same application, and add the following context-param into the web.xml.



Thursday, January 28, 2016

Throw ValidatorException in JSF Validator

When throwing exception from a validator,
remember to throw ValidatorException instead of FacesException,
else the message component might be not able to display the correct validation message.

public void validAbc(FacesContext context, UIComponent component, Object value) {

   // some validation logic
  if(value.equals("abc")) {
    // proceed 
  } else {
    throw  new ValidatorException(new FacesMessage(
        FacesMessage.SEVERITY.ERROR, null, "validation error message"));


Wednesday, January 6, 2016

Simple Captcha by PrimeFaces graphicImage

Basically the concept is to generate random text and display it with image, which is <p:graphicImage />.

1. Write a method to generate the StreamedContent.
public StreamedContent getCaptcha() {
    StreamedContent 2dText = null;
    try {
        BufferedImage bufferedImg = new BufferedImage(
                100, 25, BufferedImage.TYPE_INT_RGB);
        Graphics2D g2 = bufferedImg.createGraphics();
        String captchaText = generateRandomString();            
        g2.drawString(captchaText, 0, 10);
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        ImageIO.write(bufferedImg, "png", os);
        2dText = new DefaultStreamedContent(
                new ByteArrayInputStream(os.toByteArray()), "image/png"); 
    catch (Exception e) {
    return 2dText;


Related Posts Plugin for WordPress, Blogger...