2013-05-27 35 views
0

插入物我不能讓它工作,從我的web界面插入對象...AppEngine上 - 爪哇 - 從Web界面

我有一個公式推,並就ok了點擊我啓動Java功能...

我EndpointClass已經follwing自動生成插入功能

@ApiMethod(name = "insertQuestion") 
public Question insertQuestion(Question question) 
{ 
    EntityManager mgr = getEntityManager(); 
    try 
    { 
     if (containsQuestion(question)) 
     { 
      throw new EntityExistsException("Object already exists"); 
     } 
     mgr.persist(question); 
    } 
    finally 
    { 
     mgr.close(); 
    } 
    return question; 
} 

,我有一個簡單的問題類

@Id 
@GeneratedValue(strategy = GenerationType.IDENTITY) 
private Key key; 

private String question; 

private String answerCorrect; 
private String answerWrong1; 
private String answerWrong2; 
private String answerWrong3; 

public Question(String question, String answerCorrect, String answerWrong1, String answerWrong2, String answerWrong3) 
{ 
    this.question = question; 
    this.answerCorrect = answerCorrect; 
    this.answerWrong1 = answerWrong1; 
    this.answerWrong2 = answerWrong2; 
    this.answerWrong3 = answerWrong3; 

} 

// + all the getters and setters... 

我嘗試添加它像我的網頁如下:

var question = document.formQuestion.elements[0]; 
var answer = document.formQuestion.elements[1]; 
var answerWrong1 = document.formQuestion.elements[2]; 
var answerWrong2 = document.formQuestion.elements[3]; 
var answerWrong3 = document.formQuestion.elements[4]; 

var q2 = new Object(); 
q2.question = question; 
q2.answerCorrect = answer; 
q2.answerWrong1 = answerWrong1; 
q2.answerWrong2 = answerWrong2; 
q2.answerWrong3 = answerWrong3; 
gapi.client.questionendpoint.insertQuestion({q2}).execute(handleMessageResponse); 
//gapi.client.questionendpoint.insertQuestion(q2).execute(handleMessageResponse); 
//gapi.client.questionendpoint.insertQuestion({"question": q2}).execute(handleMessageResponse); 

但(我想和所有其他的東西),沒有工作......

有人可以告訴我怎麼做是否正確?

回答

1

你不應該在對象「q2」周圍花括號。你在哪裏添加答案的對象q2? q2必須具有與您在端點中期望的對象相同的屬性。 另外; 您是否導入了Javascript客戶端庫,否則gapi將不起作用。 您還試圖通過https://.appspot.com/_ah/api/discovery/v1/apis發現API,這會爲其他端點提供網址。 另一個非常好的工具是API Explorer,它可以針對本地主機(調試),並部署版本使用兩種:https://developers.google.com/apis-explorer/?base=https://your_base_url/_ah/api#p/

希望這有助於

+0

好吧,我編輯我的職務,並加入我忘了線補充,描述q2如何初始化的行...我現在沒有使用括號圍繞q2嘗試它,但是那一項沒有工作......我甚至嘗試過使用'gapi.client.question q2 = new gapi。 client.question(問題,答案,答案錯誤1,答案錯誤2,答案錯誤3);'但是,這也沒有工作... gapi工作到目前爲止,我可以列出表格中的所有內容,並且工作正常...也許你有另一個提示?我會看看api資源管理器...也許這可以幫助我... – prom85

+1

我可以分辨一些差異。我也給了端點一個路徑,不知道它是否意味着什麼。它在你自己的機器上本地工作嗎?嘗試調試端點類並檢查它正在接收哪種對象。另請嘗試使用var req = gapi.clientquestionendpoint.insertQuestion(q2).execute(handleMessageResponse);然後用回調的新行 – user1700737

+0

也可以用var req = gapi.clientquestionendpoint.insertQuestion(q2).execute(handleMessageResponse);然後用回調lile的新行req.execute(function(data){});並檢查數據對象是否有任何內容。 – user1700737