user5532967
user5532967

Reputation:

Form subclasses in codename one

I'm building an app in Codename one. I'm trying to both create a Form in the codename one resource GUI and specify its type used in code. Background is to be able to specify dynamically which data is used in the form.

Is this recommended and is there a recommended way to accomplish that?

Currently I'm digging into the codenameone code and it looks like one way would be to pass a custom-made resource to the StateMachine/UIBuilder. The UIBuilder asks the resource for the component type and use this to return a custom type, and register the custom form types with lines like

UIBuilder.registerCustomComponent("MyForm",com.myapp.MyForm.class);

Any suggestions to this?

Upvotes: 0

Views: 56

Answers (1)

Shai Almog
Shai Almog

Reputation: 52770

Right now the only way to do this in the old GUI builder is to replace all the forms with your new Form subclass which could be fine for many cases. E.g. override this in the state machine:

protected Component createComponentInstance(String componentType, Class cls) {
    if(cls == From.class) {
        return new MyForm();
    }
    return super.createComponentInstance(componentType, cls);
}

Notice that we are in the process of moving to a new more traditional GUI builder, right now its in technology preview state (translation: buggy as hell and lots of missing features) but this should be trivial in the future. See:

https://www.codenameone.com/blog/new-gui-builder.html

https://www.codenameone.com/blog/gui-builder-walkthru.html

https://www.codenameone.com/blog/terse-syntax-migration-wizard-more.html

Upvotes: 0

Related Questions