【问题标题】:struts2 dynamic tabbed panel Action not getting calledstruts2动态选项卡式面板动作没有被调用
【发布时间】:2013-11-01 20:04:36
【问题描述】:

我正在 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>

我需要的是单击在 struts.xml 文件中定义的选项卡 2 testAction 被调用。 由于此操作,home.jsp 页面应设置在 Tab2 中。 Tab2 数据来自数据库,因此在单击时应调用此选项卡操作类。

<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>

但在标签 2 Error loading '/testAction.action' (404 Not Found) 显示。单击 tab2 时不会调用 TestAction 类。

我的要求是单击每个选项卡,相应的操作类应该被调用,并且在 struts.xml 文件中映射的 jsp 应该显示在相应的选项卡式窗格中。

请帮助我。如果您可以提供显示上述场景的 struts2 选项卡式窗格 simple 示例,敬请期待。

提前致谢。

【问题讨论】:

  • 使用&lt;s:url&gt; 标签。可以升级 S2 版本并使用 struts2-jquery-plugin 吗?

标签: ajax struts2 struts2-jquery


【解决方案1】:

如果你想使用ajax,你可以使用Struts2 Jquery Plugin

Struts2 Jquery Tabbed Panel Examples

如果你想解决当前的情况,那么很明显,没有找到该动作,这意味着url is wrong。您可能想要查找命名空间和其他路径错误。

【讨论】:

  • 是的,它按照您给定的选项卡式面板示例工作。为此,我需要修改 jar 文件。
  • 但是上面代码中描述了为什么它没有被调用的以下行。
  • 我已经明确检查了jsp文件中的以下代码。该操作正在调用 请点击此处。
【解决方案2】:

以下代码调用动作类 testAction 和 testAction2。唯一的事情是我需要将我的罐子升级到以下。调用动作类后,映射到动作类的jsp会显示在相应的选项卡式面板中。

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 和 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>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-29
    • 1970-01-01
    • 1970-01-01
    • 2022-01-01
    相关资源
    最近更新 更多