HstComponent Java Class

The HstComponent class defines the contract for components used in the Bloomreach Content HST container. The HST container invokes an HstComponent during three request lifecycle phases: ACTION, RESOURCE, and RENDER.

Thread Safety

HstComponent instances are not thread-safe. The HST container creates a single instance of each HstComponent per component configuration, and this instance serves all concurrent requests. Do not store request-specific data in instance variables. If you must use instance variables, ensure they are safe for concurrent access. Storing request-specific objects as instance variables usually leads to concurrency issues.

Instantiation Behavior

The HST container creates one HstComponent instance for each component configuration. For example, if you define two component configurations (under hst:myproject/hst:configurations/{myproject}/hst:pages or hst:myproject/hst:configurations/{myproject}/hst:components) that both specify hst:componentclassname as com.myproject.components.Detail, the container will instantiate Detail.java twice—once for each configuration.

HstComponent Interface

A custom HstComponent must implement the following interface:

public interface HstComponent { /** * Allows the component to initialize itself * * @param servletContext the servletConfig of the HST container servlet * @param componentConfig the componentConfigBean configuration * @throws HstComponentException */ void init(ServletContext servletContext, ComponentConfiguration componentConfig) throws HstComponentException; /** * This method is invoked before {@link #doBeforeRender(HstRequest, HstResponse)} method to give an HstComponent * a chance to <i>prepare</i> any business service invocation(s). * This method can be implemented to prepare business content objects by creating asynchronous jobs in parallel * without having to wait each component's {@link #doBeforeRender(HstRequest, HstResponse)} execution sequentially. * * @param request * @param response * @throws HstComponentException */ default void prepareBeforeRender(HstRequest request, HstResponse response) throws HstComponentException { } /** * Allows the component to do some business logic processing before rendering * * @param request * @param response * @throws HstComponentException */ void doBeforeRender(HstRequest request, HstResponse response) throws HstComponentException; /** * Allows the component to process actions * * @param request * @param response * @throws HstComponentException */ void doAction(HstRequest request, HstResponse response) throws HstComponentException; /** * Allows the component to do some business logic processing before serving resource * * @param request * @param response * @throws HstComponentException */ void doBeforeServeResource(HstRequest request, HstResponse response) throws HstComponentException; /** * Allows the component to destroy itself * * @throws HstComponentException */ void destroy() throws HstComponentException; /** * Returns the ComponentConfiguration for this component or <code>null</code> * if not implemented by a subclass */ default ComponentConfiguration getComponentConfiguration() { return null; } }

Key Methods

The most commonly implemented methods in custom components are doBeforeRender and doAction. These methods handle the primary business logic for rendering and processing actions, respectively.

Inheritance and Default Implementations

Custom components typically extend org.hippoecm.hst.component.support.bean.BaseHstComponent, which itself extends org.hippoecm.hst.core.component.GenericHstComponent. The GenericHstComponent provides default (empty) implementations of the interface methods and does not add specific behavior. If you do not specify the hst:componentclassname property in your configuration, the container uses GenericHstComponent by default.

BaseHstComponent does not provide additional behavior for doBeforeRender, doAction, or doBeforeServeResource, but it does include common utility methods for component development. The getComponentConfiguration method is already implemented in GenericHstComponent and typically does not need to be overridden.

Share Feedback
Page: /build/component-development/hstcomponent-java-class
Section: Build
Category *