Documentation Center

Registering custom module in DXA

Once you created custom models and views you must register them in SDL Digital Experience Accelerator.

About this task

Procedure

  1. Created a class which inherits form the AbstractInitializer class.
  2. In your newly created class, define an initialize function annotated with the @PostConstruct annotation.
  3. In the function you created, register all views and entity models which are used with these views.

Example of the initialization code

package com.sdl.dxa.modules.test;

import com.sdl.dxa.modules.test.model.CustomPageModelImpl;
import com.sdl.dxa.modules.test.model.CustomRegionModelImpl;
import com.sdl.dxa.modules.test.model.ExternalContentLibraryStubSchemaflickr;
import com.sdl.dxa.modules.test.model.VimeoVideo;
import com.sdl.webapp.common.api.model.ViewModelRegistry;
import com.sdl.webapp.common.api.model.entity.Article;
import com.sdl.webapp.common.api.model.region.RegionModelImpl;
import com.sdl.webapp.common.impl.AbstractInitializer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
 * TestModuleInitializer
 */
@Component
public class TestModuleInitializer extends AbstractInitializer {

    @Autowired
    public TestModuleInitializer(ViewModelRegistry viewModelRegistry) {
        super(viewModelRegistry, "Test"); 
    }

    @PostConstruct
    public void initialize() {
        this.registerViewModel("VimeoVideo", VimeoVideo.class);
        this.registerViewModel("ShowClaims", Article.class);
        this.registerViewModel("GeneralPageCustomRegion", CustomPageModelImpl.class);
        this.registerViewModel("CustomPageMetadata", CustomPageModelImpl.class);
        this.registerViewModel("CustomRegion", CustomRegionModelImpl.class);
        this.registerViewModel("TestRegionView", RegionModelImpl.class);
    }
}

What to do next

Your custom module is register in DXA. You can start using it in the web application.