Search code examples
javagwtproxyuibinder

GWT: Querying and translating proxied UI classes into widgets


This morning I asked this question and received a really great answer for it. I'm now trying to prototype the design and am running into a similar (but not same) issue. Essentially I'm trying to have a 100% configuration-driven GWT UI, where changes to a DB can produce radically different UIs but without any code changes.

My architecture is simple:

  • I will use a separate tool (or at first, by hand) to produce a .xul (XUL) file and save it to a database; probably a document database like Mongo or something similar
  • On the server-side, I will write a XulParser that reads the XUL file out of the database and turns it into a ContainerProxy instance
    • A ContainerProxy is my "proxy" equivalent to a com.google.gwt.user.client.ui.Panel or something similar; it is just a bean/POJO that contains a list of other widget proxies (see code snippet below)
    • For instance, I might have a XUL file that defines a Button like the one below
    • This ButtonProxy would be added to a ContainerProxy (along with any other UI widgets in the same container/view/panel)
  • On the client-side, I'll query for the ContainerProxy somehow (???), and pull it down from the server.
  • I'll then have a mechanism that translates each of the ContainerProxy's children (the ButtonProxy, etc.) into actual UI widgets.

This way, at first I can put a certain XUL file into the database and the UI might only contain the "Order Now" button on it. But down the road, I might want to use a totally different UI, so I design a different XUL file, update the document in the database, and - voila - the UI changes for all users without any code changes. Please note: I understand this is not a normal way of doing things: I have a special use case where I need such config-driven UIs.

To help clarify the XUL-parsing process:

<button id="order" label="orderNow" clickHandler="org.myapp.OrderButtonHandler" />

after the XulParser reads the above snippet, we get:

ButtonProxy orderButton = new ButtonProxy("order", "OrderNow");
orderButton.addClickHandler(new OrderButtonHandler());

Anyways, my questions:

  1. What do I need to do on the client-side to query for my ContainerProxy? Can anyone provide pseudo-code to help me visualize it?
  2. Once I have the ContainerProxy on the client-side, what UI mechanisms are available for me to translate the proxied classes into actual UI widgets? Is UIBinder available? Again, can someone provide some pseudo-code?

Thanks in advance for any help here!


Solution

  • Here is a bit of a code idea that would do what you wanted. I haven't tested this, but you can get the idea of how it all could work together from it.

        String htmlFragment = "<div><button id='action1' type='button>Action 1<button/><div/>";
    
        HTMLPanel container = new HTMLPanel(htmlFragment);
    
        RootLayoutPanel.get().add(container);
    
        Element button1El = container.getElementById("action1");
    
        if(button1El != null){
            Button button1 = Button.wrap(button1El);
            button1.addClickHandler(new ClickHandler(){
    
                @Override
                public void onClick(ClickEvent event) {
                    // What you want button 1 to do
                }
    
            });
        }