以编程方式访问JSF和Primefaces版本号

alf*_*onx 6 primefaces facescontext jsf-2

我使用PrimeFaces 3.5.x和Mojarra JSF 2.1.x我想以编程方式访问和显示这两个库的版本.

我使用版本作为maven2属性,但我希望有一个更简单的方法来获得版本.我希望找到类似的东西:

Primeface.getVersion();
FacesContext.getCurrentInstance();
Run Code Online (Sandbox Code Playgroud)

基于JavaScript的解决方案也可以,因为我只想在状态页面上显示版本.

Cag*_*ici 17

在PrimeFaces 4.0中,删除了Constants.VERSION以支持;

RequestContext.getCurrentInstance().getApplicationContext().getConfig().getBuildVersion();
Run Code Online (Sandbox Code Playgroud)

另外请注意FacesContext.class.getPackage().getImplementationVersion();,它不适用于某些应用服务器,如websphere.


Xtr*_*ica 8

对于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();
Run Code Online (Sandbox Code Playgroud)

对于Primefaces 3.x,您可以使用Constantsutils包中的类:

import org.primefaces.util.Constants;

Constants.VERSION
Run Code Online (Sandbox Code Playgroud)