Struts 1

Hdiv installation steps for Struts 1 framework.

Before starting the installation check the environment setup.

Add Hdiv Dependencies

Add Hdiv dependencies to the web application project. To do this, add the following dependencies to the pom.xml file.

<dependency>
    <groupId>org.hdiv.ee</groupId>
    <artifactId>hdiv-ee-core</artifactId>
    <version>${org.hdiv-ee.version}</version>
</dependency>
<dependency>
    <groupId>org.hdiv.ee</groupId>
    <artifactId>hdiv-ee-config</artifactId>
    <version>${org.hdiv-ee.version}</version>
</dependency>
<dependency>
    <groupId>org.hdiv</groupId>
    <artifactId>hdiv-struts-1</artifactId>
    <version>${org.hdiv.version}</version>
</dependency>

Note

Replace ${org.hdiv-ee-version} and ${org.hdiv.version} variables with the ones sent by our support team.

Copy TLD files

Hdiv has its own TLD files with the same Struts 1 tags but with Hdiv integration activated. To enable Hdiv the application have to load Hdiv TLD files instead Struts original ones.

Copy TLD files from folder META-INF inside hdiv-struts-1-x.x.x.jar library into the project, for example, in this location: /WEB-INF/tld/.

Files:

  • hdiv-html.tld
  • hdiv-logic.tld
  • hdiv-nested.tld
  • hdiv-tiles.tld

XML Config

Modify the web.xml file to include the Listener and the Hdiv filter:

<!-- Hdiv Init Listener -->
<listener>
    <listener-class>org.hdiv.listener.InitListener</listener-class>
</listener>
<!-- Hdiv Validator Filter -->
<filter>
    <filter-name>ValidatorFilter</filter-name>
    <filter-class>org.hdiv.filter.ValidatorFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>ValidatorFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

It is important that Hdiv's Listener should go after Spring's Listener ContextLoaderListener.

Add the Hdiv configuration file to the rest of Spring configuration files:

<!-- Spring Context Loader -->
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
        /WEB-INF/application-context.xml
        /WEB-INF/hdiv-config.xml
    </param-value>
</context-param>
  1. Create the Hdiv configuration file. This file is an XML file that follows the format of Spring configuration files. For convention, its name should be hdiv-config.xml, located in the WEB-INF directory and its minimal content is as follows:

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:hdiv="http://www.hdiv.org/schema/hdiv-ee"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.hdiv.org/schema/hdiv-ee
    http://www.hdiv.org/schema/hdiv/hdiv-ee.xsd">
        <!-- Hdiv Base Configuration -->
        <hdiv:config excludedExtensions="css,png,gif,js,woff">
            <hdiv:startPages>/</hdiv:startPages>
        </hdiv:config>
        <!-- Own Editable Validation -->
        <hdiv:editableValidations>
            <hdiv:validationRule url="/.*" />
        </hdiv:editableValidations>
    </beans>
    
  2. Use Hdiv TLD files.

    Replace Struts tld files with Hdiv tlds.

    <!-- Replace Struts 1 tld with Hdiv tlds -->
    <jsp-config>
        <taglib>
            <taglib-uri>http://struts.apache.org/tags-html</taglib-uri>
            <taglib-location>/WEB-INF/tld/hdiv-html.tld</taglib-location>
        </taglib>
        <taglib>
            <taglib-uri>http://struts.apache.org/tags-logic</taglib-uri>
            <taglib-location>/WEB-INF/tld/hdiv-logic.tld</taglib-location>
        </taglib>
        <taglib>
            <taglib-uri>http://struts.apache.org/tags-nested</taglib-uri>
            <taglib-location>/WEB-INF/tld/hdiv-nested.tld</taglib-location>
        </taglib>
    </jsp-config>
    

    Note

    After a TLD replacement, a complete JSP recompilation is required. Force your server working folder cleanup.