Apache MyFaces has a really easy mechanism for determining the version, but Mojarra does not have something like a "Version" class. I went looking through the Mojarra implementation looking for a way to determine it easily. I then asked Manfred Riem, Oracle, how to determine the version. He sent me a response that I thought was unbelievably simple and I thought I would share it. I have also added it to my library of utilities I have for JSF.
JSF Utilities Library on Bitbucket: jsf-utils
Here is the code for your enjoyment. Simple and sweet...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | /** * This method provides a convenient means of determining the JSF * Specification version. * * @return JSF Specification version, e.g. 2.1 * @since 1.5 */ public static String getSpecificationVersion() { return FacesContext.getCurrentInstance().getClass().getPackage().getSpecificationVersion(); } /** * This method provides a convenient means of determining the JSF * Implementation version. * * @return JSF Implementation version, e.g. 2.1.26 * @since 1.5 */ public static String getImplementationVersion() { return FacesContext.getCurrentInstance().getClass().getPackage().getImplementationVersion(); } /** * This method provides a convenient means of determining the JSF * Implementation Title. * * @return JSF implementation title, e.g. Mojarra. * @since 1.5 */ public static String getImplementationTitle() { return FacesContext.getCurrentInstance().getClass().getPackage().getImplementationTitle(); } |
Update: If you are using OmniFacesframework, the Faces class has a method to determine implementation version.
0 comments :
Post a Comment