-1

I have been able to create an application with Struts 2 and tiles 2.1 and complete the login action so far. Now I need to be able to click on a button and perform an action. I have configured the action-method-namespace mapping as per the guides out there but every guide has the same example and same configuration. I am having a difficult time trying to understand and troubleshoot this one.

Please check my configuration below

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="true" />
    <constant name="struts.devMode" value="true"/>
    <constant name="struts.custom.i18n.resources" value="ApplicationResources"/>
    <!-- <constant name="struts.enable.SlashesInActionNames" value="true" /> -->
    <constant name="struts.mapper.alwaysSelectFullNamespace" value="true" />

    <package name="logindefault" extends="struts-default">
        <result-types>
         <result-type name="tiles" class="org.apache.struts2.views.tiles.TilesResult"/>
        </result-types>
        <action name="login" method="execute" class="com.schenker.ocean.actions.LoginAction">
            <result name="success" type="tiles">baseLayout</result>
            <result name="input">/login.jsp</result>
            <result name="fail">/login.jsp</result>
        </action>

    </package>

    <package name="default" extends="logindefault" namespace="/">
        <result-types>
         <result-type name="tiles" class="org.apache.struts2.views.tiles.TilesResult"/>
        </result-types>
        <action name="login" method="execute" class="com.schenker.ocean.actions.LoginAction">
            <result name="success" type="tiles">baseLayout</result>
            <result name="input">/login.jsp</result>
            <result name="fail">/login.jsp</result>
        </action>
    </package>

    <package name="dashboard" extends="logindefault" namespace="dashboard">
        <result-types>
         <result-type name="tiles1" class="org.apache.struts2.views.tiles.TilesResult"/>
        </result-types>
        <action name="getDashboard" method="getDashboard" class="com.schenker.ocean.actions.Dashboard">
            <result name="success" type="tiles1">dash</result>
            <result name="input">/login.jsp</result>
            <result name="fail">/login.jsp</result>
        </action>
    </package>
</struts>

tiles.xml

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

<!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="/baseLayout.jsp">
      <put-attribute name="title"  value="Template"/>
      <put-attribute name="header" value="/header.jsp"/>
      <put-attribute name="leftmenu"   value="/leftmenu.jsp"/>
      <put-attribute name="body"   value=""/>
      <put-attribute name="footer"   value="/footer.jsp"/>
   </definition>

   <definition name="dash" extends="baseLayout">
      <put-attribute name="title"  value="dash"/>
      <put-attribute name="body"   value="/viewBody.jsp"/>      
   </definition>

   <definition name="assign" extends="baseLayout">
      <put-attribute name="title"  value="Assign"/>
      <put-attribute name="body"   value="/assignBody.jsp"/>      
   </definition>

</tiles-definitions>

left menu.jsp

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" HREF="css/styles.css">
</head>
<body>          
    <table width="20%" align="left">
    <s:form name="searchForm" action="dashboard/getDashboard" method="post">
        <tr>
            <th align="center" colspan="2">Search</th>
        </tr>
        <tr>
             <td colspan="1"><s:textfield size="20" maxlength="20" name="stt" key="label.stt"></s:textfield> </td>
        </tr>
        <!-- <tr>

        </tr> -->
        <tr>
            <td colspan="1"><s:textfield size="20" maxlength="20" name="hawb" key="label.hawb"></s:textfield> </td>
        </tr>
        <!-- <tr>

        </tr> -->
        <tr>
            <td colspan="1"><s:textfield size="20" maxlength="20" name="chi" key="label.chi"></s:textfield> </td>
        </tr>
        <!-- <tr>

        </tr> -->
        <tr>
            <td colspan="1"><s:textfield size="20" maxlength="20" name="invoice" key="label.invoice"></s:textfield> </td>
        </tr>
        <!-- <tr>

        </tr> -->
        <tr>
            <td colspan="1"><s:textfield size="20" maxlength="20" name="shipment" key="label.shipment"></s:textfield> </td>
        </tr>
        <!-- <tr>

        </tr> -->
        <tr>
            <td align="right" style="padding-top: 2px;" colspan="2"><s:submit key="label.search" method="getDashboard" ></s:submit> </td>
        </tr>
    </s:form>
    </table>
</body>
</html>

folder structure

enter image description here

I have been trying for the past few days so please help me out without telling me to go check google.. I keep getting this

no dashboard/getDashboard action configured in namespace /

Why?

I tried moving the getDashboard action declaration to 'logindefault' and 'default' packages.

It gives me different ways of saying the same thing.

Roman C
  • 49,761
  • 33
  • 66
  • 176
DJR
  • 454
  • 2
  • 8
  • 29

1 Answers1

1

You are doing several strange things, but your main problem is that you need to specify the namespace separately, then instead of

<s:form action="dashboard/getDashboard" method="post">

use

<s:form action="getDashboard" namespace="dashboard" method="post">

After that, you are using a login action in "" namespace and another one in "/" namespace, redefining exactly the same tiles result that you are inheriting because of extends="logindefault", starting action names with get, using alwaysSelectFullNamespace in a strange way, enabling DMI, that is discouraged, without actually needing to use it, etc.

Change also

<s:submit key="label.search" method="getDashboard" ></s:submit>

to

<s:submit key="label.search" />

Because you've already defined the getDashboard method as the one to call when calling the getDashboard action.

My 2 cents: If I were you I'd restart from scratch, without tiles, making a clean, full working small project with 3-4 pages to use as future reference. And please, remove those tutorial sites from the bookmarks...

Andrea Ligios
  • 49,480
  • 26
  • 114
  • 243