Here's a simple enough example of how to use the <sj:a> tag available in the struts2-jquery plugin (v 3.2.1)
http://www.weinfreund.de/struts2-jquery-showcase/index.action


Well what I get though  is somehow mysterious (to me).

The first time when I call the action [1] given by its URL http://localhost:8080/myApp/test/me
I get the correct server response, that is

- a line saying "Echo: Hello me!"
- underneath it a textfield containig the phrase "Hello me !"
- followed by a submit button

This is what it looks like:
Before: http://i40.tinypic.com/vf8782.jpg

Nice.

But after I submit the form the textfield and the submit button get somehow mysteriously duplicated! (but not the "Echo:..." textline)

So there's still the initial textfield with the updated Hello + whatever-you-typed-in phrase but yet another textfield and yet another submit button.

The only difference I can tell between the initial and the duplicated textfield is that the latter never gets a refresh.
It always contains the initial "Hello me !" phrase.

This is how it looks like after the submit:
After: http://i41.tinypic.com/2ji44j.jpg

Maybe someone can tell what I'm missing here.
Thanks!


[1] http://pastebin.com/Wq0Ek1H4 <http://pastebin.com/Wq0Ek1H4>(Action class)

[2] http://pastebin.com/6yF2xwu4 (jsp)

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------

[1] ACTION class

package xxx.actions.yyy;

import org.apache.log4j.Logger;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Actions;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;

import com.opensymphony.xwork2.ActionSupport;

@Namespace("/test")
public class HelloWorldAction extends ActionSupport {

    public String getYourName() {return yourName; }
    public void setYourName(String value) {this.yourName = value;}

    @Actions({
@Action(value="{yourName}", results={@Result(location = "test.jsp")}),
        @Action(value="put", results={@Result(location = "test.jsp")})
    })
    public String execute() {
        yourName = "Hello " +  yourName + " !";
        logger.debug("execute: " + yourName);
        return SUCCESS;
    }

    private static final long serialVersionUID = 1L;
    private String yourName;
private static Logger logger = Logger.getLogger(HelloWorldAction.class);

}


[2] (jsp)
----------------------------------------------------------------------------------------------------------------------

<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib prefix="sj" uri="/struts-jquery-tags"%>

<html>

<head>
<sj:head/>
</head>

<body>

<div id="formResult">
<p>Echo : ${yourName}</p>
</div>

<s:form id="form" action="put">
<s:textfield id="echo" name="yourName"/>
</s:form>

<sj:a
            id="ajaxformlink"
            formIds="form"
            targets="formResult"
            indicator="indicator"
            button="true"
            buttonIcon="ui-icon-gear"
>
            Submit form here
</sj:a>

<img id="indicator" src="images/indicator.gif" alt="Loading..." style="display:none"/>

</body>

</html>





Reply via email to