GWT:我如何获得动态制作的文本框的更新值

时间:2022-05-16 15:20:34

I am creating a TextBox dynamically ,I get the values from server ,values could be 5,some times 10 etc , so No of textboxes i create will be different..

我正在动态创建一个TextBox,我从服务器获取值,值可能是5,有时候是10等,所以我创建的文本框中没有它会有所不同。

After all textboxes created .

创建完所有文本框后。

There is an update button in page , When i click on this update button , Whatever changes user may have entered in any of the textBox,should Need to go to the server .. That I am not able to do ..

页面中有一个更新按钮,当我点击此更新按钮时,无论用户可能在任何textBox中输入了什么更改,都应该需要去服务器..我无法做到..

below is the code where i create the textBoxes

下面是我创建textBoxes的代码

 public void fetchData(){
    public void onSuccess(ArrayList<Details> result) {
          for(int i =0;i<result.size();i++){


                name  = new TextBox();
                name.setText(result.get(i).getName());
                                    verticalPanel.add(name);
                                    namesList.add(name);
                                    }}

Suppose name value is at this time : admin Now user goees to the UI and change admin to adminNew then click update button

假设此时的名称值为:admin现在,用户返回UI并将admin更改为adminNew,然后单击“更新”按钮

Here what i do on update Button

这是我在更新Button上所做的

                public void Update(){

                     for(int i =0;i<namesList.size(); i++){
         String updatedNanme = namesList.get(i).getText());
    }

}

Now how will I get the updated name which user have changed from UI(i.e adminNew), in updatedName field. Right now i am getting the old name(i.e admin) which i got from fetchData Method.

现在,我将如何在updatedName字段中获取用户从UI(即adminNew)更改的更新名称。现在我得到了从fetchData方法获得的旧名称(即admin)。

thanks

2 个解决方案

#1


0  

You should get textbox's value by calling getText(), not the "old value". I think there's a problem with your textbox list. maybe instantiate the textbox two times! I suggest you debug your code, put a breakpoint on when textbox is instantiated and when the update occures. See if both are the same instance (for example if you're using eclipse watching a variable, id of the variable is shown in front of it. this is the object's id for VM. check if id of textbox that was instantiated is the same as id of textbox you are getting value from)

您应该通过调用getText()而不是“旧值”来获取文本框的值。我认为你的文本框列表有问题。也许两次实例化文本框!我建议您调试代码,在实例化文本框时以及更新发生时设置断点。看看两者是否是同一个实例(例如,如果你使用eclipse看变量,变量的id显示在它前面。这是VM的对象id。检查实例化的文本框的id是否相同作为文本框的id你从中得到了价值)

#2


0  

Could it be possible that you override the content of text box with the user entry ? Your update method will always set updatedNanme to the content of the last element from your namesList array. And how do you access the updatedNanme string ? This string is only available in the for loop ?

您是否可以使用用户条目覆盖文本框的内容?您的更新方法将始终将updatedNanme设置为namesList数组中最后一个元素的内容。你如何访问updatedNanme字符串?该字符串仅在for循环中可用?

#1


0  

You should get textbox's value by calling getText(), not the "old value". I think there's a problem with your textbox list. maybe instantiate the textbox two times! I suggest you debug your code, put a breakpoint on when textbox is instantiated and when the update occures. See if both are the same instance (for example if you're using eclipse watching a variable, id of the variable is shown in front of it. this is the object's id for VM. check if id of textbox that was instantiated is the same as id of textbox you are getting value from)

您应该通过调用getText()而不是“旧值”来获取文本框的值。我认为你的文本框列表有问题。也许两次实例化文本框!我建议您调试代码,在实例化文本框时以及更新发生时设置断点。看看两者是否是同一个实例(例如,如果你使用eclipse看变量,变量的id显示在它前面。这是VM的对象id。检查实例化的文本框的id是否相同作为文本框的id你从中得到了价值)

#2


0  

Could it be possible that you override the content of text box with the user entry ? Your update method will always set updatedNanme to the content of the last element from your namesList array. And how do you access the updatedNanme string ? This string is only available in the for loop ?

您是否可以使用用户条目覆盖文本框的内容?您的更新方法将始终将updatedNanme设置为namesList数组中最后一个元素的内容。你如何访问updatedNanme字符串?该字符串仅在for循环中可用?