Search code examples
gwtarraylistrpcgwt-rpc

Sending an ArrayList as a parameter in GWT-RPC


I tried sending an ArrayList to an RPC service in GWT but keeps on failing. Here is my code fragment

                greetingService.addNewQuestion(questionnaireKey, questionText, qcList, new AsyncCallback<Boolean>(){
                @Override
                public void onFailure(Throwable caught) {
                    Window.alert("Something went wrong!\n"+caught.getMessage());

                }
                @Override
                public void onSuccess(Boolean result) {
                    Window.alert("Question Added!");
                }

            });

QuestionChoice is a simple object with no method, and qcList is an ArrayList of QuestionChoice

public class QuestionChoice implements IsSerializable{
/**
 * 
 */
private static final long serialVersionUID = 5668640935838672293L;
public String text;
public boolean isCorrect;

public QuestionChoice(){

}
public QuestionChoice(String text, boolean isCorrect){
    this.text = text;
    this.isCorrect = isCorrect;
}

}

Has anyone tried sending an ArrayList as a parameter in GWT-RPC? If you do, please try to post your sample code here. Thank you.


Solution

  • Yes, It is possible to send an ArrayList as a parameter in GWT-RPC call. When developing the GWT-RPC code, a lot of times you may encounter errors when a request in GWT-RPC is invoked, this is due to a change in GWT-RPC service that may have not been corresponds to the clients compiled GWT-RPC definition. To solve this issue you have to restart your development server whenever you changed your codes in the server side classes, or in the GWT-RPC service defintion(ie GreetingService, GreetingServiceAsync and in GreetingServiceImpl)