How to upgrade WildFly JSF version with Galleon

This article will teach you how to add MyFaces 4 (or newer) support to your WildFly installation using Galleon features pack. At the end of it, you will be able to complete the upgrade of your JSF implementation in no time!

Choosing a different JSF Implementation in WildFly

Out of the box, WildFly ships with a “main” JSF implementation which varies according to the version of the application server:

[standalone@localhost:9990 /] /subsystem=jsf:list-active-jsf-impls()
{
    "outcome" => "success",
    "result" => [
        "main"
    ]
}

To install a different JSF implementation generally requires installing manually both the JSF API and Implementation as a module, then configure the jsf subsystem to use that implementation as default:

/subsystem=jsf/:write-attribute(name=default-jsf-impl-slot,value=myfaces-impl-4.0.0)

{
    "outcome" => "success",
    "response-headers" => {
        "operation-requires-reload" => true,
        "process-state" => "reload-required"
    }
}

In this tutorial we will learn how to simplify this process by using the Galleon tool. If you are new to Galleon shell, we recommend checking this article: Provisioning WildFly with Galleon

Provisioning MyFaces 4 or newer

Firstly, you need to download the latest version of Galleon from here: https://github.com/wildfly/galleon/releases

Next, unpack it and create the following XML file to provision a custom version of WildFly:

<?xml version="1.0" ?>
<installation xmlns="urn:jboss:galleon:provisioning:3.0">
  <!-- Configure WildFly version -->
  <feature-pack location="org.wildfly:wildfly-galleon-pack:29.0.0.Final">

    <default-configs inherit="true"/>
    <packages inherit="true"/>
  </feature-pack>

  <!-- Configure MyFaces Feature Pack version -->

  <feature-pack location="org.wildfly:wildfly-myfaces-feature-pack:1.0.0.Beta1">
    <default-configs inherit="true"/>
    <packages inherit="true"/>
  </feature-pack>
  <config model="standalone" name="standalone.xml">
    <layers>
      <!-- Base layer -->
      <include name="management"/>
      <include name="myfaces"/>
    </layers>
  </config>
  <options>
    <option name="optional-packages" value="passive+"/>
    <option name="jboss-fork-embedded" value="true"/>
  </options>
</installation>

Notice the two variables you can customize in this XML file:

Then, you can install WildFly 29 with MyFaces 4 as follows:

./galleon.sh provision myfaces_server.xml --dir=/home/jboss/wildfly29-myfaces4

At the end of it, WildFly will be available in the folder /home/jboss/wildfly29-myfaces4

Testing the new JSF version

Start WildFly and check the JSF implementation from the Console:

how to change wildfly version

This is also visible by querying the jsf subsystem:

/subsystem=jsf:list-active-jsf-impls()
{
    "outcome" => "success",
    "result" => [
        "myfaces",
        "main"
    ]
}

You can verify that “myfaces” is the default implementation as follows:

[standalone@localhost:9990 /] /subsystem=jsf:read-attribute(name=default-jsf-impl-slot)
{
    "outcome" => "success",
    "result" => "myfaces"
}

Finally, here is a trick to check the current JSF implementation (which includes the version) programmatically:

FacesContext facesContext = FacesContext.getCurrentInstance();

// Get the Implementation Title, which usually contains the JSF implementation name
String implementationTitle = facesContext.getClass().getPackage().getImplementationTitle();

FacesMessage facesMsg = new FacesMessage(FacesMessage.SEVERITY_INFO, "JSF Implementation "+implementationTitle, null);
FacesContext.getCurrentInstance().addMessage(null, facesMsg);

Here is the FacesMessage which contains the JSF Implementation and version:

configuring jsf version wildfly

Lastly, you can also configure the JSF implementation declaratively in your Web application by setting the org.jboss.jbossfaces.JSF_CONFIG_NAME context parameter to your JSF implementation,

<context-param>
    <param-name>org.jboss.jbossfaces.JSF_CONFIG_NAME</param-name>
    <param-value>myfaces</param-value>
</context-param>

Conclusion

The Galleon tool’s user-friendly CLI and feature packs simplify the provisioning process, making it accessible to developers and administrators of all levels. Its ability to manage complex configurations and handle transitive dependencies ensures that you can easily create reproducible and consistent JSF runtimes tailored to your project’s unique requirements.

Found the article helpful? if so please follow us on Socials