Question

I am creating a tabbed pane with as follows in struts 2(struts2-core-2.0.11.jar).

   <%@ taglib prefix="s" uri="/struts-tags" %>
  <html>  
      <head>
      <s:head theme="ajax" debug="true"/>
      </head>

      <body>

      <s:tabbedPanel id="test" >

      <s:div id="one" label="Tab 1" theme="ajax">
           First Tab
      </s:div>

      <s:div id="two" label="Tab 2" theme="ajax" href="/testAction.action">
       <s:form name="second" >
           second Tab 
       </s:form>
      </s:div>

      <s:div id="three" label="Tab 3" theme="ajax">
         3rd Tab
      </s:div>
     </s:tabbedPanel>
      </body>
</html>

what i need is on clicking the Tab 2 testAction gets called which is defined in the struts.xml file. As a result of this action, home.jsp page should set in Tab2. Tab2 data is coming from the database hence on clickng this tab action class should gets called.

<struts>
    <include file="struts-default.xml"/>
    <package name="a" extends="struts-default">
        <action name="resultAction" class="com.test.LogingEx">
            <result name="success">/success.jsp</result>
            <result name="error">/error.jsp</result>      
        </action>

        <action name="testAction" class="com.test.TestAction">
            <result name="success">/home.jsp</result>

        </action>

    </package>
</struts>

But on the tab 2 Error loading '/testAction.action' (404 Not Found) is getting displayed. TestAction class is not getting called on clicking of tab2.

My requirement is on clicking the each tab respective action class should get called and jsp mapped in struts.xml file should gets display on respective tabbed pane.

Please help me on this. Appriciate if you can provide struts2 tabbed pane simple example which shows above scenario.

Thanks in advance.

Was it helpful?

Solution 2

The following code calls the action class testAction and testAction2. The only thing is i need to upgrade my jars to the following. After calling the action class jsp mapped to the action class is showing in the respective tabbed panel.

commons-fileupload-1.2.1.jar, commons-logging-1.0.4.jar, freemarker-2.3.8.jar, ognl-2.6.11.jar, struts2-core-2.1.8.1.jar, struts2-jquery-plugin-3.6.1.jar and xwork-core-2.1.6.jar

<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="sj" uri="/struts-jquery-tags"%>
<html>
  <head>
    <sj:head />
  </head>
  <body>
    <s:url var="remoteurl1" action="testAction.action"/>
    <s:url var="remoteurl2" action="testAction2.action"/>

    <sj:tabbedpanel id="remotetabs" selectedTab="1" show="true" hide="'fade'" collapsible="true" sortable="true">
        <sj:tab id="tab1" href="%{remoteurl1}" label="Remote Tab One"/>
        <sj:tab id="tab2" href="%{remoteurl2}" label="Remote Tab Two"/>
    </sj:tabbedpanel>
  </body>
</html>

OTHER TIPS

If you wish to use ajax, you can use the Struts2 Jquery Plugin

Struts2 Jquery Tabbed Panel Examples

If you want to solve the current situation, then it's pretty clear, that the action is not found, that means the url is wrong. You might want to look for namespace & other path errors.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top