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.

<context-param>
    <param-name>org.jboss.jbossfaces.WAR_BUNDLES_JSF_IMPL</param-name>
    <param-value>true</param-value>
</context-param>


Done!!

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"));
  }
}



Done!!

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) {
        e.printStackTrace();
    }
    return 2dText;
}


Tuesday, December 29, 2015

How to parameterized label from resource bundle

Assuming we have a of labels to be displayed by type.
label.type.a = This is label A label.type.b = This is label B label.type.c = This is label C label.type.d = This is label D

To display the label by type in xhtml, the simplest way it to use a rendered attribute
<h:outputLabel value="#{lbl['label.type.a']}" rendered="#{myType == 'A'}" /> <h:outputLabel value="#{lbl['label.type.b']}" rendered="#{myType == 'B'}" /> <h:outputLabel value="#{lbl['label.type.c']}" rendered="#{myType == 'C'}" /> <h:outputLabel value="#{lbl['label.type.d']}" rendered="#{myType == 'D'}" />

Instead of using the above sample, I would prefer to use two lines to achieve the same effect.
especially when the list of type are long. 
<ui:param name="typeLabel" value="label.type.#{myType}" /> <h:outputLabel value="#{lbl['typeLabel']}" />


Done!!

Monday, December 14, 2015

Google Maps' icon not rendered in Liferay 6.2

When using Google Maps in Liferay  6.2.
All the icon in Google Maps are not rendered,
This is due to css conflict in Liferay 6.2 and Google Maps.

To resolve this problem, just need to add the following css.
.aui .gm-style img {
  max-width: none;
}


Done!!

LinkWithin

Related Posts Plugin for WordPress, Blogger...