PDA

View Full Version : AsyncCallback return a HorizontalPanel to a DisclosurePanel



Glyndwr
7 Aug 2016, 3:55 PM
I want to return a HorizontalPanel to a DisclosurePanel from an AsyncCallback on the client side. The code I have is (note the commented out addressDisclosurePanel.add(addressHorizontalPanel) which is the part I need to work):

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;
}

Regards,

Glyn

programsline
27 Feb 2017, 4:39 PM
i hope you will get help