Why async service dont fill check-box form panel?

69 views Asked by At

I am developing an GWT app and when user clicks on button, form panel with checkboxes should appear. Those checkboxes should be filled with list of items from async service. But when I open form panel I dont have those checkboxes. I debugged and saw that result from my service is not here on time, but later list is full.. Here is the code:

     @Override
        public void createBody() {


            GWT_ACCESS_ROLE_SERVICE.findByUserId(null, currentSession.getSelectedAccount().getId(), userId, new AsyncCallback<PagingLoadResult<GwtAccessRole>>() {

                @Override
                public void onFailure(Throwable caught) {
                    // TODO Auto-generated method stub

                }

                @Override
                public void onSuccess(PagingLoadResult<GwtAccessRole> result) {
                  lista   = result.getData();
                    for (GwtAccessRole gwtAccessRole : lista) {
                     bb = new CheckBox();
                        bb.setBoxLabel(gwtAccessRole.getRoleName());
                    }
                    FormPanel roleFormPanel = new FormPanel(FORM_LABEL_WIDTH);
                    roleFormPanel.add(bb);

                    bodyPanel.add(roleFormPanel);

                }
            });

        }

What am I doing wrong and why my checkboxes are not filled? Thanks in advance.

EDIT: When I debug, this method GWT_ACCESS_ROLE_SERVICE.findByUserId is shown AFTER Form Panel appears. So Form Panel apperas and after that debug goes to this my method and does all the stuff.

2

There are 2 answers

4
WLGfx On

It should look something like this then:

import java.util.logging.Logger;

final Logger log = Logger.getLogger("LOG OUTPUT");

@Override
public void onSuccess(PagingLoadResult<GwtAccessRole> result) {

    if (result == null) {
        log.info("No data from the server");
        return;
    }

    lista   = result.getData();

    FormPanel roleFormPanel = new FormPanel(FORM_LABEL_WIDTH);

    for (GwtAccessRole gwtAccessRole : lista) {
        bb = new CheckBox();
        bb.setBoxLabel(gwtAccessRole.getRoleName());
        roleFormPanel.add(bb);

        // display on the JS console output
        log.info("CheckBox added to roleFormPanel");
    }

    bodyPanel.add(roleFormPanel);

    // confirm panel being added
    log.info("Panel added to body");
}

.gwt.xml module will have these lines added:

<inherits name="com.google.gwt.logging.Logging"/>
<set-property name="gwt.logging.enabled" value="TRUE"/> 

You were not adding anything to the form panel as the checkbox had gone out of scope.

EDIT: added logging output information

0
Denis Vabishchevich On

Note that FormPanel is implement HasOneWidget, so if you try to put one more widget to container it will override it