Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access JSF and Primefaces version numbers programmatically

I use PrimeFaces 3.5.x and Mojarra JSF 2.1.x I would like to access and show the versions of both libraries programmatically.

I use the versions as maven2 properties, but I hope there is an easier way to get the versions. I hope to find something like:

Primeface.getVersion();
FacesContext.getCurrentInstance();

A JavaScript based solution would be fine too, since I only want to display the version on a status page.

like image 816
alfonx Avatar asked Aug 21 '13 11:08

alfonx


3 Answers

In PrimeFaces 4.0, Constants.VERSION is removed in favor of;

RequestContext.getCurrentInstance().getApplicationContext().getConfig().getBuildVersion();

Also watch out for FacesContext.class.getPackage().getImplementationVersion();, it doesn't work on some app servers like websphere.

like image 60
Cagatay Civici Avatar answered Sep 19 '22 03:09

Cagatay Civici


For JSF:

//returns the major version (2.1)
FacesContext.class.getPackage().getImplementationVersion();

//returns the specification version (2.1)
Package.getPackage("com.sun.faces").getSpecificationVersion();

//returns the minor implementation version (2.1.x)
Package.getPackage("com.sun.faces").getImplementationVersion();

For Primefaces 3.x you can use the Constants class in utils package:

import org.primefaces.util.Constants;

Constants.VERSION
like image 10
Xtreme Biker Avatar answered Sep 22 '22 03:09

Xtreme Biker


For PrimeFaces, you can use the Constants class:

org.primefaces.util.Constants.VERSION
like image 4
LaurentG Avatar answered Sep 20 '22 03:09

LaurentG