Question

What can be provided to the location attribute of a

<c:SimplePager ui:field='pager' location='HERE' /> 

I tryed CENTER, but it didnt work, I see in the expense sample app that they dont have a location attribute but instead set it on the creation of it in the UiBinder. But I cant do that since its a required attribute. What to do?

Was it helpful?

Solution

You must provide SimplePager.TextLocation, which can be CENTER, LEFT or RIGHT.

<c:SimplePager ui:field='pager' location='CENTER'/>

OTHER TIPS

The only solution I see at the moment is working with @UiField(provided = true). Not sure if that is of any help but check out the small example below anyway.

The ui.xml:

<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder" xmlns:g="urn:import:com.google.gwt.user.client.ui"
    xmlns:c="urn:import:com.google.gwt.user.cellview.client">
    <ui:style>

    </ui:style>
    <g:HTMLPanel>
        <c:CellList ui:field="list" />
        <c:SimplePager ui:field="pager" />
        <g:Button ui:field="more" text="addMore" />
    </g:HTMLPanel>
</ui:UiBinder>

and the widget:

public class TestView extends Composite {

    private static TestViewUiBinder uiBinder = GWT.create(TestViewUiBinder.class);

    interface TestViewUiBinder extends UiBinder<Widget, TestView> {}

    @UiField(provided = true)
    CellList<String> list;
    @UiField(provided = true)
    SimplePager pager;
    @UiField
    Button more;
    private int counter = 0;
    private ListDataProvider<String> provider;

    public TestView() {
        list = new CellList<String>(new TextCell());
        pager = new SimplePager();
        initWidget(uiBinder.createAndBindUi(this));
        provider = new ListDataProvider<String>(getList());
        provider.addDataDisplay(list);
        pager.setDisplay(list);
        pager.setPageSize(5);
    }

    private LinkedList<String> getList() {
        LinkedList<String> list = new LinkedList<String>();
        list.add("1st");
        list.add("2nd");
        list.add("3rd");
        list.add("4th");
        list.add("5th");
        return list;
    }

    @UiHandler("more")
    void onMoreClick(ClickEvent event) {
        provider.getList().add(++counter + " more");
    }
}

The SimplePager class can't be instantiated by UiBinder, because it doesn't have a setter for Location to fix the error.

An alternative to @UiField(provided=true), which allows the variable to be instantiated automatically is by creating a factory method to instruct the page outside of UiBinder on how to instantiate and if needed setup the object.

Here's an example of the factory method it will apply to any @UiField SimplePager class. @UiField(provided=true) would handle multiple varying instantiations, but for one UiFactory is the simplest, because you don't have to be concerned with when the variable is used.

@UiFactory SimplePager createSimplePager() {
    return new SimplePager(TextLocation.CENTER);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top