0

I have a homepage with a modal struts 2 jquery dialog which calls a struts2 action containing a struts form.

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
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. <sj:head /> has to be removed in the addNewItem JSP to avoid conflict with the homepage.

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.

How can I solve this?

Edit:

Struts config

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

user1277546
  • 8,652
  • 3
  • 17
  • 25

1 Answers1

0

First of all, give your elements unique id-s. As pointed out in Quincy comment. Second, in your struts.xml file change action name to addNewItem instead of AddNewItem.

Aleksandr M
  • 24,264
  • 12
  • 69
  • 143
  • I tried this change, but it makes no difference. The main problem seems to be whether or not is included but the layout/styling conflicts when it is included again in the addNewItem JSP. – user1277546 Dec 04 '12 at 19:11
  • So include it only in one JSP and use another for dialog form. – Aleksandr M Dec 04 '12 at 19:44
  • Post complete JSP code with correct struts.xml configuration. What you are showing now would not work because of different action names and results to others JSP-s. – Aleksandr M Dec 04 '12 at 20:30
  • if I include it in only one JSP then the tags do not get processed in the JSP without it. – user1277546 Dec 05 '12 at 00:15
  • But you are using JSP without `` inside JSP WITH head tag. It is very difficult to help you when you are not showing complete code. Post you full JSP code. – Aleksandr M Dec 05 '12 at 14:56
  • I solved the issue: I needed to use on the sub pages to avoid conflicts. Thanks for your help anyway :) – user1277546 Dec 05 '12 at 22:13