7

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.

Cœur
  • 37,241
  • 25
  • 195
  • 267
alfonx
  • 6,936
  • 2
  • 49
  • 58

4 Answers4

17

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.

LaurentG
  • 11,128
  • 9
  • 51
  • 66
Cagatay Civici
  • 6,406
  • 1
  • 29
  • 34
10

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
Community
  • 1
  • 1
Aritz
  • 30,971
  • 16
  • 136
  • 217
  • Thanks. For JSF your solution only returns "2.1". To get the minor version as well, I found this: Package.getPackage("com.sun.faces").getImplementationVersion() which returns "2.1.25". – alfonx Aug 21 '13 at 16:52
  • As mentioned in the answer by @Cagatay this constant was removed in version 4.0 of Primefaces. – mrswadge Aug 22 '16 at 13:27
4

For PrimeFaces, you can use the Constants class:

org.primefaces.util.Constants.VERSION
LaurentG
  • 11,128
  • 9
  • 51
  • 66
4

If you need to get the Version on runtime, there will not be any instance of RequestContext. Therefore you could use the ImplementationVersion of the package:

Package.getPackage("org.primefaces").getImplementationVersion()

If the package cannot be resolved, you can try to resolve the version via PrimeFaces class:

PrimeFaces.class.getPackage().getImplementationVersion()
Alexander Bering
  • 603
  • 1
  • 6
  • 11