My last presentation at the German ADF Partner Community showed how to put a version number into an application ear and allows two versions of the same application to exist on a managed WebLogic Server. One question I got from the audience was how to show this version in the UI of the application. This blog post shows one way of doing this.
For those readers which do not know how to put a version number into an application EAR before deploying it to a WLS, lets start with this.
Andrejus Baranovskis has a blog post How to set EAR Version for ADF Application on WebLogic about this which uses a more hand coded approach. Edwin Biemond showed a small ant script to do is. I will show you a different solution using ANT.
This solution consists of a general GeneralVersionBuild.xml ANT script and a project dependent VersoinBild.xml ANT script which sets some properties (the version properties) for the GeneralVersionBuild.xml. The GeneralVersionBuild.xml defines the targets to alter the different version numbers you define for your applications and print out the version in the log like
Versioninfo:
[echo] VERSION: V1.0.0.3 DB.V1 vom 2012/02/12 21:09
[echo] Major: 1
[echo] Minor: 0
[echo] Fix: 0
[echo] Build: 3
[echo] Date: 2012/02/12 21:09
[echo] DB-Schema Version: 1
[echo] --------------------------------------------------------------------------------------------------
The information above is the complied from the version.properties file which defines the different parts of the version number:
#Build version info
#Sun Feb 12 16:06:18 CET 2012
DBSchema=1
majorVersion=1
fixVersion=0
minorVersion=1
buildDate=2012/02/12 16\:06
buildNum=39
To manipulate the properties we use the targets defined in the GeneralVersionBuild.xml ANT script. This is called by the project dependent VersionBuild.xml ANT script:
<?xml version="1.0" encoding="UTF-8" ?>
<project name="AVIVersionBuild" default="make" basedir=".">
<!-- # Relativ path to the base of the application -->
<property name="root.dir" value=".."/>
<property name="earFileBaseName" value="BlogAccessVersionInfo"/>
<!-- PATH TO VERSION.PROPERTIES FILE (e.g.: src/de/hahn/blogxxxx/view/version.properties) -->
<property name="file.version.properties" value="src/de/hahn/blog/accessversioninfo/view/version.properties"/>
<property file="${file.version.properties}"/>
<property name="deployFolder" value="../deploy/"/>
<!-- PATH TO THE GENERAL VERSION BUILD ANT SCRIPT -->
<import file="${root.dir}/Versionierung/GeneralVersionbuild.xml"/>
</project>
All we need to do is to set the Versionbuild.xml file as ANT’Project Buildfile’ file

Setup Ant Project Buildfile
Now that the project has a version.properties file (at src/de/hahn/blog/accessversioninfo/view/version.properties) holding information about the current version of the application we need a way to access this information on a page in the UI. As we are using a property file we can bind this file as resource bundle into the project and access the parts (properties) with EL.
To add the version.properties file as resource bundle we open the project properties, select the ‘Resource Bundle’ node and then set the properties from the bundle as outputText onto the page.
Make sure that you select the right project when you add a property file.

Add a property file as bundle
Next search for the version.properties file in the project

Select version.properties
Now in the page we can access the property via EL. We drag an outputText component on the page and select its value from Resource bundle

Select a value from resource bundle

Select value from property file
This will create this entry in your page
<c:set var="aviviewcontrollerBundle"
value="#{adfBundle['de.hahn.blog.accessversioninfo.view.version']}"/>
and here is the resulting outputText:
<af:outputText value="Version: #{aviviewcontrollerBundle.majorVersion}.#{aviviewcontrollerBundle.minorVersion}.#{aviviewcontrollerBundle.fixVersion}.#{aviviewcontrollerBundle.buildNum} from #{aviviewcontrollerBundle.buildDate}" id="ot6"/>
and the resulting page when you run the application

Running application
As you see the name of the resource bundle is set to ‘aviviewcontrollerBundle’ (the default bundle name). This happens if you don’t already have a default bundle defined which contains a key value pair. You can rename it to e.g. ‘versioninfo’ to make clear what the bundle is used for. In this case you have to change the EL to access to properties too.
<c:set var="versioninfo"
value="#{adfBundle['de.hahn.blog.accessversioninfo.view.version']}"/>
…
<af:panelGroupLayout id="pgl2">
<af:outputText value="Version: #{versioninfo.majorVersion}.#{versioninfo.minorVersion}.