Translate

July 30, 2013

(Yet) another JSF gotcha or how important it is to know the JSF lifecycle

Why is some code evaluated when it is in a tag that is "rendered=false"


Background

With my team, we are working on a pretty big application in JSF where some people have more experience in front-end (JSF) and some in the back-end side (web service client). 
One of them got a problem that some JSF was evaluated inside a "rendered=false" tag. That setup is working some other places and didn't see why it was not working here.


The cause

The problem was that, inside the tag that was not supposed to be evaluated, there was an <ui:include>.
The origin of this is that ui:include runs at view build time and redered attribute is evaluated in the render response phase (that is the last phase of the lifecycle). This means that the ui:include is evaluated before rendered attribute.

The (broken) code

 <h:panelgroup rendered="#{backingBean.shouldShow}">  
   <ui:include src="pageA.xhtml"/>  
 </h:panelgroup>  
 <h:panelgroup rendered="#{!backingBean.shouldShow}">  
   <ui:include src="pageB.xhtml"/>  
 </h:panelgroup>  


The solution

There are 2 ways to go around this problem:
1. You could replace the ui:include with the code within the target page. This is probably not the best way as you might duplicate some code or make it more difficult to read.
2. You can use c:if or c:choose instead of the rendered attribute


The (working) code

 <c:choose>  
   <c:when test="#{backingBean.shouldShow}">  
     <ui:include src="pageA.xhtml"/>  
   </c:when>  
   <c:otherwise">  
     <ui:include src="pageB.xhtml"/>  
   </c:otherwise>  
 </c:choose>  


For more information

You can contact us at OSnode.

Auto build PrimeFaces from source with Bamboo

How to use the latest version of PrimeFaces in your projects

Building from source in Bamboo

Background

A little while back, we wanted to use the latest version of Primefaces where some bugs where fixed but the built library was not available so we decided to build from source. It is quite easy to do manually but we wanted to automate the process. So what we did was to add a build in our CI: Bamboo. We have an internal maven repository (Nexus).
We want to be able to add PrimeFaces SNAPSHOTS to our projects

Original setup

We have Nexus installed and it is defined in our settings.xml so we can access our own builds. In addition, we have a Bamboo server (this setup should work with other CI).

Requirement

On the Bamboo server, you need to have perl installed and added as an executable in the Bamboo admin

The build

  1. You need to define the repository. For now, it is http://primefaces.googlecode.com/svn/primefaces/trunk/ I add it as a shared repository in Bamboo but it is not necessary. You can define it in the plan.
  2. Add the checkout task - no special configuration here
  3. Here is the trick: we need to replace the distributionManagement tag to deploy it to our own repository. This is done with perl. Create a "Command" task with the perl executable and add these argiment: -pi -e 'BEGIN{undef $/;} s/.*<\/distributionManagement>/your-distributionManagement-tag-goes-here/smg' pom.xml
    Note that all forward slash "/" needs to be escaped with a backslah i.e: http:\/\/www.repo.com\/path\/to\/repo
  4. Next, you create a maven task that runs clean deploy

That's it

Now you are ready to go with the newest PrimeFaces available in your projects. As a side note, I added a trigger to run this plan every week only if new code has been commited.

For more information

You can contact us at OSnode.