2013-08-03 16 views
0

我有一個包含多個文本字段和「註冊」按鈕的表單。codenameone如何在addArgument命令中引用字段內容

當按下注冊按鈕時,我想將字段的內容發送到網站svc。

我已成功連接到我的web服務並傳遞硬編碼的post變量。

我無法獲得正確的語法addArgument傳遞文本字段的內容。

舉例來說,如果我有一個表格(註冊),並在該表格上我有一個文本字段(txtFirstName),

什麼是對txtFirstName字段的內容添加到addArgument命令的語法?

我的代碼如下:

@Override 
protected void onRegister_BtnRegisterAction(Component c, ActionEvent event) { 
    // register new user 
    ConnectionRequest r = new ConnectionRequest(); 
    r.setUrl("http://localhost/ihsnj/websvc.php"); 
    r.setPost(true); 

    r.addArgument("R", "Y"); // R = register 
    // this is the line generating the error <cannot find symbol> 
    r.addArgument("FirstName",txtFirstName.getText()); 

    InfiniteProgress prog = new InfiniteProgress(); 
    Dialog dlg = prog.showInifiniteBlocking(); 
    r.setDisposeOnCompletion(dlg); 
    NetworkManager.getInstance().addToQueueAndWait(r); 


} 

回答

0

你的問題是不相關的ConnectionRequest。您需要使用不是字段的查找方法,因爲只有在窗體實際顯示時才構建組件(以保留RAM)。

使用findTxtFirstName(c).getText()作爲第二個參數例如爲:

req.addArgument("first_name", findTxtFirstName(c).getText()); 
+0

我仍然得到找不到字段符號。我正在編輯問題並添加我的實際代碼... –

+0

我編輯了我的答案以反映您的編輯 –

相關問題