gpt4 book ai didi

java - 方法内出现 AsyncCallback 的 GWT Java 错误

转载 作者:行者123 更新时间:2023-12-01 09:37:20 34 4
gpt4 key购买 nike

在客户端,我向服务器端发出调用,以获取数据库中的名称列表。当此列表返回到客户端时,我会在 TabPanel 中显示每个名称。当显示每个名称时,我向服务器端发出调用,以从服务器端的数据库中获取该名称的地址列表(这样我就可以更新和添加)。返回地址列表后,我将它们添加到 DisclosurePanel 内的 FlexTable 中。

所以我有一个包含名称的 TabPanel 和一个包含关联地址的 DisclosurePanel。

问题是我无法在 DisclosurePanel 方法中调用数据库来获取正确的地址。

代码是:

private DisclosurePanel addressDisclosurePanel(String nameId) {
DisclosurePanel addressDisclosurePanel = new DisclosurePanel("Address");

//Get the Addresses
AsyncCallback<List<Address>> callback = new GetAddressHandler<List<Address>>();
rpc.getAddressList(nameId, callback);


class GetAddressHandler<T> implements AsyncCallback<List<Address>> {
//Get the list of Addresses.
PersonalDetailsView view;

public GetAddressHandler(PersonalDetailsView view) {
this.view = view;
}

public void onFailure(Throwable ex) {
System.out.println("RPC call failed - GetAddressHandler - Notify Administrator.");
Window.alert("Connection failed - please retry.");
}
public void onSuccess(List<Address> result) {
view.renderAddresses(result);
}
}

public void renderAddresses(List<Address> addressList) {
//Load each TabPanel with Addresses

final FlexTable flexTableAddress = new FlexTable();

if (addressList == null || addressList.isEmpty()) {
//Add a place to add an address

//Address Type
final Label lblAddressType = new Label("Address Type:");
lblAddressType.setStyleName("gwt-Label-Login");
flexTableAddress.setWidget(0, 0, lblAddressType);

final TextBox textBoxAddressType = new TextBox();
textBoxAddressType.setStyleName("gwt-TextBox");
textBoxAddressType.setWidth("300px");
flexTableAddress.setWidget(0, 1, textBoxAddressType);

addressDisclosurePanel.add(flexTableAddress);

}else{
int row = 0;
//
//Create a place to display each Address and allow update
//
for (final Address eachAddress : addressList) {
//Store key
final String addId = eachAddress.getAddId();

//Address Type
final Label lblAddressType = new Label("Address Type:");
lblAddressType.setStyleName("gwt-Label-Login");
flexTableAddress.setWidget(row, 0, lblAddressType);

final TextBox textBoxAddressType = new TextBox();
textBoxAddressType.setText(eachAddress.getAddType());
textBoxAddressType.setStyleName("gwt-TextBox");
textBoxAddressType.setWidth("300px");
flexTableAddress.setWidget(row, 1, textBoxAddressType);

row++;
}
addressDisclosurePanel.add(flexTableAddress);
}
}
return addressDisclosurePanel;
}

错误上线:

view.renderAddresses(result);

错误消息是“PersonalDetailsView 类型的 renderAddresses(List) 方法未定义”。

上线:

public void renderAddresses(List<Address> addressList) {

错误消息是“此行有多个标记 - 标记“)”上的语法错误,;预期的 - 标记“(”上的语法错误;预期 - void 是变量的无效类型 渲染地址”

我做了这个改变:

    private DisclosurePanel addressDisclosurePanel(String nameId) {
final DisclosurePanel addressDisclosurePanel = new DisclosurePanel("Address");

//Get the Addresses
AsyncCallback<List<Address>> callback = new GetAddressHandler<List<Address>>(PersonalDetailsView.this);
rpc.getAddressList(nameId, callback);

//addressDisclosurePanel.add(addressHorizontalPanel);

return addressDisclosurePanel;
}

class GetAddressHandler<T> implements AsyncCallback<List<Address>> {
//Get the list of Addresses.
PersonalDetailsView view;

final HorizontalPanel addressHorizontalPanel = new HorizontalPanel();

public GetAddressHandler(PersonalDetailsView view) {
this.view = view;
}

public void onFailure(Throwable ex) {
System.out.println("RPC call failed - GetAddressHandler - Notify Administrator.");
Window.alert("Connection failed - please retry.");
}
public void onSuccess(List<Address> result) {
Window.alert("Render address.");
addressHorizontalPanel.add(view.renderAddresses(result));
}
}

private FlexTable renderAddresses(List<Address> addressList) {
//Load each TabPanel with Addresses
Window.alert("get address.");;

final FlexTable flexTableAddress = new FlexTable();

if (addressList == null || addressList.isEmpty()) {
//Add a place to add an address

//Address Type
final Label lblAddressType = new Label("Address Type:");
lblAddressType.setStyleName("gwt-Label-Login");
flexTableAddress.setWidget(0, 0, lblAddressType);

final TextBox textBoxAddressType = new TextBox();
textBoxAddressType.setStyleName("gwt-TextBox");
textBoxAddressType.setWidth("300px");
flexTableAddress.setWidget(0, 1, textBoxAddressType);

}else{
int row = 0;
//
//Create a place to display each Address and allow update
//
for (final Address eachAddress : addressList) {
//Store key
final String addId = eachAddress.getAddId();
Window.alert("addId = " + addId);

//Address Type
final Label lblAddressType = new Label("Address Type:");
lblAddressType.setStyleName("gwt-Label-Login");
flexTableAddress.setWidget(row, 0, lblAddressType);

final TextBox textBoxAddressType = new TextBox();
textBoxAddressType.setText(eachAddress.getAddType());
textBoxAddressType.setStyleName("gwt-TextBox");
textBoxAddressType.setWidth("300px");
flexTableAddress.setWidget(row, 1, textBoxAddressType);

row++;
}
}
return flexTableAddress;
}

那么我如何返回地址:

class GetAddressHandler<T> implements AsyncCallback<List<Address>> {

到披露面板?

最佳答案

您不能在方法内声明类。所以改变:

   //Get the Addresses
AsyncCallback<List<Address>> callback = new GetAddressHandler<List<Address>>();
rpc.getAddressList(nameId, callback);


class GetAddressHandler<T> implements AsyncCallback<List<Address>> {
//Get the list of Addresses.
PersonalDetailsView view;

public GetAddressHandler(PersonalDetailsView view) {
this.view = view;
}

public void onFailure(Throwable ex) {
System.out.println("RPC call failed - GetAddressHandler - Notify Administrator.");
Window.alert("Connection failed - please retry.");
}
public void onSuccess(List<Address> result) {
view.renderAddresses(result);
}
}

至:

//Get the Addresses
AsyncCallback<List<Address>> callback = new AsyncCallback<List<Address>> {
//Get the list of Addresses.
PersonalDetailsView view;

public GetAddressHandler(PersonalDetailsView view) {
this.view = view;
}

public void onFailure(Throwable ex) {
System.out.println("RPC call failed - GetAddressHandler - Notify Administrator.");
Window.alert("Connection failed - please retry.");
}
public void onSuccess(List<Address> result) {
view.renderAddresses(result);
}
}
rpc.getAddressList(nameId, callback);

希望我的编辑中没有语法错误;)

关于java - 方法内出现 AsyncCallback 的 GWT Java 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38764221/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com