简体   繁体   English

在struts2 jquery对话框中使用带有更多struts2 jquery元素的动作

[英]struts2-jquery Using an action with further struts2 jquery elements inside a struts2 jquery dialog

I have a homepage with a modal struts 2 jquery dialog which calls a struts2 action containing a struts form. 我有一个带模式struts 2 jquery对话框的主页,该对话框调用包含struts表单的struts2动作。

Homepage dialog code 主页对话框代码

<s:url id="newItemURL" var="newItemURL" action="addNewItem" />
<sj:dialog id="newItem" href="%{newItemURL}" title="Create New Item" width="700" position="top" autoOpen="false"
                        loadingText="Loading..." />
<sj:a id="addNewItem" openDialog="newItem" button="true" buttonIcon="ui-icon-refresh">New Item</sj:a>

addNewItem Action Result JSP addNewItem操作结果JSP
This form submits and produces a text result if successful. 如果成功,此表单将提交并生成文本结果。

   <div id="newItemForm">
        <s:form action="addNewItem" id="addNewItem">
            <fieldset>
            <legend>Create a new item</legend>
            <label for="description">Description: </label>
                <s:textarea id="description" name="item.description" label="Description:" cols="20" rows="5"/><br />
                <sj:submit id="submitNewItem" targets="resultNewItem" value="Submit" indicator="indicator" button="true" replaceTarget="true" />
            </fieldset> 
        </s:form>
    </div>
    <div id="resultNewItem"></div>

The addNewItem form works fine standalone with <sj:head /> , with AJAX result appearing in the resultNewItem div. addNewItem表单可以与<sj:head />独立运行,并且AJAX结果显示在resultNewItem div中。 <sj:head /> has to be removed in the addNewItem JSP to avoid conflict with the homepage. 必须在addNewItem JSP中删除<sj:head />以避免与主页冲突。

The issue is when addNewItem Action is included as part of the dialog upon submitting the form the homepage action is called and as a result I end up with another homepage inside the dialog. 问题是,在提交表单时会在对话框中包括addNewItem Action作为对话框的一部分,因此会调用主页操作,结果我在对话框中得到了另一个主页。

How can I solve this? 我该如何解决?

Edit: 编辑:

Struts config Struts配置

    <action name="homepage"
        class="com.actions.Homepage">
        <result name="success" type="tiles">Homepage</result>
    </action>

    <action name="AddNewItem" class='com.actions.AddNewItem'> 
        <result name="success">/WEB-INF/jsp/addNewRisk/addNewRisk.jsp</result>
    </action>

    <action name="smoAddNewRiskINSERT" class="com.actions.AddNewItem" method="addNewRisk"> 
        <result name="success">/WEB-INF/jsp/addNewRisk/success.jsp</result>
        <result name="error">/WEB-INF/jsp/addNewRisk/error.jsp</result>
    </action>

What I want to achieve User clicks button to load dialog, addNewItem form is created (AddNewItem action), when user submits form it is sent via AJAX submit button and the result is displayed within the dialog. 我要实现的目标用户单击按钮以加载对话框,创建了addNewItem表单(AddNewItem操作),当用户提交表单时,它是通过AJAX提交按钮发送的,结果显示在对话框中。

First of all, give your elements unique id-s. 首先,给您的元素唯一的ID。 As pointed out in Quincy comment. 正如昆西指出的那样。 Second, in your struts.xml file change action name to addNewItem instead of AddNewItem . 其次,在您的struts.xml文件中,将操作名称更改为addNewItem而不是AddNewItem

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM