struts2apache-tomeestruts2-jquerytiles2

How to modify the paths in struts-dojo and/or struts-jquery (Struts 2.3.20.1)?


here my development settings before I start with my problem:

Now my problem:

I want to use the DateTimePicker in Struts2-Dojo or *-JQuery, but for both API I get false paths in the generated HTML sides.

Look at these pictures what my results are:

Struts 2 - DOJO (1st Browser view, 2nd HTML src) Struts2-DOJO Browser view Struts2-DOJO HTML src

Struts 2 - JQuery (1st Browser view, 2nd HTML src) Struts2 - JQuery Browser view Struts2 - JQuery HTML src

You see my problem? The double dashes? Why did Struts that? Is that a problem with Tiles?

I need only one dash, I looked up on this community before on this link: Relative Path in Struts 2 - DOJO

... and test this (you can see that under BaseLayout.jsp below) and it doesn't work for my problem.

Here my web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
         version="2.4">
    <display-name>Struts Tiles 2 Demo</display-name>
    <context-param>
        <param-name>tilesDefinitions</param-name>
        <param-value>/WEB-INF/tiles.xml</param-value>
    </context-param>

    <listener>
        <listener-class>org.apache.struts2.tiles.StrutsTilesListener</listener-class>
    </listener>

    <filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
</web-app>

The struts.xml:

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE struts PUBLIC
        "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
        "http://struts.apache.org/dtds/struts-2.3.dtd">

<struts>
    <constant name="struts.enable.DynamicMethodInvocation" value="false"/>
    <constant name="struts.devMode" value="false"/>

    <!--suppress InjectedReferences -->
    <package name="default" extends="struts-default" namespace="/">
        <result-types>
            <result-type name="tiles" class="org.apache.struts2.views.tiles.TilesResult"/>
        </result-types>

        <default-action-ref name="start"/>

        <action name="start">
            <result name="success" type="tiles">index</result>
            <result name="error" type="tiles">err404</result>
        </action>

        <action name="err404">
            <result name="success" type="tiles">err404</result>
        </action>

        <action name="dbTest">
            <result name="success" type="tiles">dbTest</result>
            <result name="error" type="tiles">err404</result>
        </action>

        <action name="dtpJQ">
            <result name="success" type="tiles">dtpJQ</result>
            <result name="error" type="tiles">err404</result>
        </action>
    </package>
</struts>

The tiles.xml:

<!DOCTYPE tiles-definitions PUBLIC
        "-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN"
        "http://tiles.apache.org/dtds/tiles-config_2_0.dtd">

<tiles-definitions>

    <definition name="baseLayout" template="/WEB-INF/tiles/layouts/BaseLayout.jsp">
        <put-attribute name="title" value="" />

        <put-attribute name="header" value="/WEB-INF/tiles/parts/Header.jsp" />
        <put-attribute name="menu" value="/WEB-INF/tiles/parts/Menu.jsp" />

        <put-attribute name="body" value="" />
        <put-attribute name="footer" value="/WEB-INF/tiles/parts/Footer.jsp" />

        <!-- only true or false -->
        <put-attribute name="isDojoActive" value="false" />
        <put-attribute name="isJQueryActive" value="false" />
    </definition>

    <definition name="index" extends="baseLayout">
        <put-attribute name="title" value=".: 1st Steps Base Layout Struts 2 :." />
        <put-attribute name="body" value="/WEB-INF/tiles/body/start.jsp" />
    </definition>

    <definition name="err404" extends="baseLayout">
        <put-attribute name="title" value=".: Test Error 404 Page :." />
        <put-attribute name="body" value="/WEB-INF/tiles/errorPages/404.jsp" />
    </definition>

    <definition name="dbTest" extends="baseLayout">
        <put-attribute name="title" value=".: DB Test :." />
        <put-attribute name="body" value="/WEB-INF/tiles/tableViews/dbTest.jsp" />
    </definition>

    <definition name="dtpTest" extends="baseLayout">
        <put-attribute name="title" value=".: Date Time Picker Test - START :." />
        <put-attribute name="body" value="/WEB-INF/tiles/body/testDTP.jsp" />
        <put-attribute name="isDojoActive" value="true" />
    </definition>

    <definition name="dtpJQ" extends="baseLayout">
        <put-attribute name="title" value=".: DTP JQ TEST :." />
        <put-attribute name="body" value="/WEB-INF/tiles/modules/dateTimePickerJQuery.jsp" />
        <put-attribute name="isJQueryActive" value="true" />
    </definition>

    <definition name="dateTimePicker" extends="baseLayout">
        <put-attribute name="title" value=".: Date Time Picker Test :." />
        <put-attribute name="body" value="/WEB-INF/tiles/modules/dateTimePicker.jsp" />
    </definition>
</tiles-definitions>

BaseLayout.jsp:

<%@page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="tiles"  uri="http://tiles.apache.org/tags-tiles" %>
<%@taglib prefix="s" uri="/struts-tags" %>
<%@taglib prefix="sx" uri="/struts-dojo-tags" %>
<%@taglib prefix="sj" uri="/struts-jquery-tags" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <title><tiles:insertAttribute name="title" ignore="true" /></title>
    <style type="text/css">@import url(/css/main.css);</style>
    <s:set var="isDojoActive"><tiles:getAsString name="isDojoActive" /></s:set>
    <s:set var="isJQueryActive"><tiles:getAsString name="isJQueryActive" /></s:set>
    <s:if test='%{#isDojoActive.equals("true")}'>
        <sx:head baseRelativePath="/struts/dojo" debug="true" parseContent="false" />
    </s:if>
    <s:if test='%{#isJQueryActive.equals("true")}'>
        <sj:head />
    </s:if>
</head>
<body>
<div class="container">
    <div id="baseLeft"><tiles:insertAttribute name="menu" /></div>
    <div id="baseRight">
        <div class="inner-content header center"><tiles:insertAttribute name="header" /></div>
        <div class="inner-content body"><tiles:insertAttribute name="body" /></div>
        <div class="inner-content footer right"><tiles:insertAttribute name="footer" /></div>
    </div>
</div>
</body>
</html>

Solution

  • I found the mistake:

    My TomEE configuration under IntelliJ IDEA:

    The missing root/application context.

    IntelliJ IDEA Server Settings for Root Context