开发者

How to use UIBinder dynamacally?

开发者 https://www.devze.com 2023-03-25 19:00 出处:网络
I am using gwt 2.3.I am using UI binder in this. I want to create grid in this by using UIBinder. For this I have written this code.

I am using gwt 2.3.I am using UI binder in this. I want to create grid in this by using UIBinder. For this I have written this code.

<g:Grid ui:field='mygrid' addStyleNames='{style.panel}'
            cellSpacing='10'>
            <g:row>
                <g:customCell>
                    <g:Label text="11" styleName="{style.label}" /> 
                </g:customCell>
                <g:customCell>
                    <g:Label text="22" styleName="{style.label}" /> 
                </g:customCell>
            </g:row>
            <g:row>
                <g:customCell>
                    <g:Label text="33" styleName="{style.label}" /> 
                </g:customCell>
                <g:customCell>
                    <g:Label text="44" styleName="{style.label}" /> 
                </g:customCell>
            </g:row>
        </g:Grid>

Now here my data of grid is static.Now In case if my data comes from server side & depending on that data I want to create a Grid using UIbinder. How can this possible ??

One another case.There is form.In that from number of controls comes from data base. So How can UIBider s开发者_如何学JAVAupport to create this form.As number of control may vary each time

So I want to know is it possible to use UIBinder in case to create User Interface depending on run time data.

Any suggestions or example appreciated.


UiBinder is "cross compiled" to JavaScript and HTML code. Once that is done you cant modify it. There is now way to do something like send your XML syntax to client and then it creates a grid.

However it is possible that you add new Rows in your "code behind".

For your second question: I have no Idea what you mean :P


Yes, you can add data into UIBinder from Java. When you created UIBinder in Eclipse it also created .java file for this XML. Edit this corresponding java file and add something like this:

public class MyGridSample extends Composite {
    // uiBinder interface declaration...
    private static MyGridSampleUiBinderUiBinder uiBinder = GWT.create(MyGridSampleUiBinder.class);

    interface MyGridSampleUiBinder extends UiBinder<Widget, MyGridSample > {
    }

    // annotation to get ui-field into code
    @UiField
    Grid mygrid;

    public MyGridSample () {
        setWidget(uiBinder.createAndBindUi(this));
        // sets cell 0,0 with label
        mygrid.setWidget(0, 0, new Label("cell 0"));
    }
}

GWT is client side framework and UIBinder is precompiled as javascript files - they are served as static files. You should make a Webservice call to get data into this template.

0

精彩评论

暂无评论...
验证码 换一张
取 消