Friday, June 22, 2012

LWUIT reloadForm()

In my app, I wanted to refresh the contents of the form (list). After looking into the UIBuilder source code, I found a method named reloadForm(). It worked as expected i.e. before method and list model init methods were called, however, it didn't put Back button in the refreshed form. To get around the issue, i implemented a method called refreshForm in StateMachine.java and added the back command explicitly. Back command addition code I got from showForm() method in UIBuilder.java. The method is as below-


private void refreshForm() {
        //reloadForm();
        Form currentForm = Display.getInstance().getCurrent();
        Form newForm = (Form) createContainer(fetchResourceFile(), currentForm.getName());
        Command backCommand = currentForm.getBackCommand();
        newForm.addCommand(backCommand, newForm.getCommandCount());
        newForm.setBackCommand(backCommand);
        beforeShow(newForm);
        Transition tin = newForm.getTransitionInAnimator();
        Transition tout = newForm.getTransitionOutAnimator();
        currentForm.setTransitionInAnimator(CommonTransitions.createEmpty());
        currentForm.setTransitionOutAnimator(CommonTransitions.createEmpty());
        newForm.setTransitionInAnimator(CommonTransitions.createEmpty());
        newForm.setTransitionOutAnimator(CommonTransitions.createEmpty());
        newForm.show();
        postShow(newForm);
        newForm.setTransitionInAnimator(tin);
        newForm.setTransitionOutAnimator(tout);
    }

I am not sure if the reloadForm() implementation has bug. I would soon put the issue in the LWUIT issue tracker.