Sunday, August 7, 2016

Return a HorizontalPanel to a DisclosurePanel when I perform an AsyncCallback

I want to return a HorizontalPanel to a DisclosurePanel when I perform an AsyncCallback. The code is (please note the commented out text I need to work - //addressDisclosurePanel.add(addressHorizontalPanel);):


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;

}

--
You received this message because you are subscribed to the Google Groups "GWT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment