Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

In this example the action "Hello" will return the string passed to it. Remember, the returned object is not the regular Struts result, it is the object that you will receive on the client side. The method can have any name.

Example:

Code Block
JAVA
JAVA
public class Hello {
    public String executehello(String text) {
        return text;
    }
}

...

Code Block
XML
XML
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>

  <constant name="struts.enable.DynamicMethodInvocation" value="false" />
  <constant name="struts.devMode" value="true" />

  <package name="example"  extends="gwt-default">
     <action name="Hello" class="example.Hello" method="hello">
        <interceptor-ref name="gwt"/>*
        <result type="void"/>*
     </action>
  </package>

</struts>

...

Code Block
JAVA
JAVA
public interface MyService extends RemoteService {
    public String executehello(String s);
}

public interface MyServiceAsync {
    public void executehello(String s, AsyncCallback callback);
}

...

Code Block
JAVA
JAVA
MyServiceAsync service = (MyServiceAsync) GWT.create(MyService.class);
AsyncCallback callback = new AsyncCallback() {
    public void onSuccess(Object result) {
        Window.alert(result.toString());
    }

    public void onFailure(Throwable caught) {
        Window.alert(caught.toString());
    }
};
ServiceDefTarget endpoint = (ServiceDefTarget) service;
endpoint.setServiceEntryPoint("Hello.action");
service.executehello("HelloHi There!", callback);

Installation

...