クラスがシリアル化されないという問題があり、代わりに GWT RPC が毎回 null を返します。タイプのオブジェクトTest
を RPC 経由で送信しようとしています。これは私のクラスです:
public class Test implements Serializable {
/**
*
*/
private static final long serialVersionUID = 2857617541722878389L;
private int testID;
private String testName;
private String testTheme;
private String subject;
private int questAmount;
private long created;
private int timer;
/**
* @gwt.typeArgs <com.nimeria.client.TestCell>
*/
private ArrayList<TestCell> tasks = new ArrayList<TestCell>();
public Test(String testName) {
super();
this.testName = testName;
}
public Test(String testName, String testTheme) {
super();
this.testName = testName;
this.testTheme = testTheme;
}
public Test(int testID, String testName, String testTheme, int questAmount,
ArrayList<TestCell> tasks) {
super();
this.testID = testID;
this.testName = testName;
this.testTheme = testTheme;
this.questAmount = questAmount;
this.tasks = tasks;
}
public int getTimer() {
return timer;
}
public void setTimer(int timer) {
this.timer = timer;
}
public String getSubject() {
return subject;
}
public void setSubject(String subject) {
this.subject = subject;
}
public long getCreated() {
return created;
}
public void setCreated(long created) {
this.created = created;
}
public Test(int testID, String testName, String testTheme, String subject,
int questAmount, long created, int timer) {
this.created = created;
this.testID = testID;
this.testName = testName;
this.testTheme = testTheme;
this.questAmount = questAmount;
this.timer = timer;
this.subject = subject;
}
public Test() {
// TODO Auto-generated constructor stub
}
public int getTestID() {
return testID;
}
public void setTestID(int testID) {
this.testID = testID;
}
public String getTestName() {
return testName;
}
public void setTestName(String testName) {
this.testName = testName;
}
public int getQuestAmount() {
return questAmount;
}
public void setQuestAmount(int questAmount) {
this.questAmount = questAmount;
}
/**
* @gwt.typeArgs <com.nimeria.client.TestCell>
*/
public ArrayList<TestCell> getTasks() {
return tasks;
}
/**
* @gwt.typeArgs tasks <com.nimeria.client.TestCell>
*/
public void setTasks(ArrayList<TestCell> tasks) {
this.tasks = tasks;
}
public String getTestTheme() {
return testTheme;
}
public void amountIncrement() {
this.questAmount++;
}
}
public class TestCell implements Serializable {
/**
*
*/
private static final long serialVersionUID = 985354326237784028L;
private int taskId;
private String quest;
private int qustionsAmount;
private int rightAnswer;
private int type;
/**
* @gwt.typeArgs <java.lang.String>
*/
private ArrayList<String> qustions = new ArrayList<String>();
public TestCell(int taskId, int qustionsAmount, int rightAnswer, int type) {
super();
this.taskId = taskId;
this.qustionsAmount = qustionsAmount;
this.rightAnswer = rightAnswer;
this.type = type;
}
public TestCell(int taskId, int qustionsAmount, int type) {
super();
this.taskId = taskId;
this.qustionsAmount = qustionsAmount;
this.type = type;
}
public TestCell(int taskId, int qustionsAmount) {
super();
this.taskId = taskId;
this.qustionsAmount = qustionsAmount;
}
public TestCell(int taskId, String quest, int qustionsAmount,
int rightAnswer, int type, String q1, String q2, String q3,
String q4, String q5) {
this.taskId = taskId;
this.quest = quest;
this.qustionsAmount = qustionsAmount;
this.rightAnswer = rightAnswer;
this.type = type;
this.qustions.add(q1);
this.qustions.add(q2);
this.qustions.add(q3);
this.qustions.add(q4);
this.qustions.add(q5);
}
public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
public int getTaskId() {
return taskId;
}
public void setTaskId(int taskId) {
this.taskId = taskId;
}
public String getQuest() {
return quest;
}
public void setQuest(String quest) {
this.quest = quest;
}
public int getQustionsAmount() {
return qustionsAmount;
}
public void setQustionsAmount(int qustionsAmount) {
this.qustionsAmount = qustionsAmount;
}
public int getQustionNumber() {
return taskId;
}
public void setQustionNumber(int qustionNumber) {
this.taskId = qustionNumber;
}
public int getRightAnswer() {
return rightAnswer;
}
public void setRightAnswer(int rightAnswer) {
this.rightAnswer = rightAnswer;
}
/**
* @gwt.typeArgs <java.lang.String>
*/
public ArrayList<String> getQustions() {
return qustions;
}
/**
* @gwt.typeArgs questions <java.lang.String>
*/
public void setQustions(ArrayList<String> qustions) {
this.qustions = qustions;
}
}
これが私の RPC 呼び出しです。
conectModule.saveTest(t, new AsyncCallback<Integer>(){
public void onFailure(Throwable caught) {
Window.alert(caught.getMessage());
Window.alert(caught.getLocalizedMessage());
}
public void onSuccess(Integer result) {
Window.alert("Тест сохранен"+result);
try {
loadTestListing();
} catch (Exception e) {
e.printStackTrace();
}
}
});