Addons

HOWTO: Override a Seam Component

Updated: December 4, 2024

This how-to considers you master the creation of the Java plug-in, and you know where to create a Java class. Otherwise please refer to the page HOWTO: create an empty bundle or use Nuxeo CLI.

The main steps to override a Seam component are:

  1. Look for the name of the Seam component you want to override. The name is the value of the annotation @name.
  2. Add an empty file named seam.properties under the folder src/main/resources of your plug-in.
  3. Create a Java class in your plug-in. It's recommended to use a custom name for your own classes, to avoid having duplicated files in your IDE for instance. But it's not mandatory providing the package containing your class is different from the default one.
  4. Overriding the default Seam component now implies three actions:

    • Reuse the same name you found in the @name annotation,
    • Reuse the same scope, unless you know what you are doing,
    • Indicate that your component will be loaded after the default one: this is done with the annotation @Install and the value Install.DEPLOYMENT (because the default component should have no value for this annotation, or value Install.FRAMEWORK).

    You should get a class structured like below:

    package org.nuxeo.sample.howto;
    
    import org.jboss.seam.annotations.Install;
    import org.jboss.seam.annotations.Name;
    import org.nuxeo.ecm.core.api.ClientException;
    import org.nuxeo.ecm.webapp.helpers.StartupHelper;
    
    @Name("startupHelper")
    @Scope(SESSION)
    @Install(precedence = Install.DEPLOYMENT)
    public class MyStartupHelper extends StartupHelper {
        private static final long serialVersionUID = 1L;
        @Override
        public String initServerAndFindStartupPage() throws ClientException {
            return super.initServerAndFindStartupPage();
        }
    }
    

In this example, we overrode the startupHelper component to write our own version of the method initServerAndFindStartupPage.


Related How-Tos
Related Documentation