Programmatic access to JSF and Primefaces version numbers

I am using PrimeFaces 3.5.x and Mojarra JSF 2.1.x I would like to access and display versions of both libraries programmatically.

I use versions as properties of maven2, 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 will also be great, as I want to display the version on the status page.

+6
source share
4 answers

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 the utils package:

 import org.primefaces.util.Constants; Constants.VERSION 
+8
source

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

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

Also keep an eye out for FacesContext.class.getPackage().getImplementationVersion(); It does not work on some application servers, such as websphere.

+15
source

For PrimeFaces you can use the Constants class:

 org.primefaces.util.Constants.VERSION 
+3
source

If you need to get the version at runtime, there will be no instance of RequestContext. Therefore, you can use the package implementation:

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

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

 PrimeFaces.class.getPackage().getImplementationVersion() 
+1
source

Source: https://habr.com/ru/post/952194/


All Articles