GWT 2.1 UiBinder SimplePager requires location attribute
Asked Answered
A

3

15

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?

Antinomian answered 17/11, 2010 at 13:44 Comment(1)
I've got no problem with it, <c:SimplePager ui:field='pager' location='CENTER' /> runsFred
I
24

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

<c:SimplePager ui:field='pager' location='CENTER'/>
Incunabula answered 23/11, 2010 at 20:55 Comment(3)
If I do it like this, and I have tried I get an other error, Ill see when I get access to the laptop with my project what exactly it is.Antinomian
I got this error if I add the location attribute : [ERROR] Class SimplePager has no appropriate setLocation() method Element <c:SimplePager location='CENTER' ui:field='pager'> (:12)Angrist
Could be because of the order of the elements. A bit late response but can save someone some time. ui:field should be before location I think.Tersina
K
5

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");
    }
}
Kwei answered 23/11, 2010 at 15:47 Comment(1)
Yep, I did it like this too, which is not an elegant solution and still my IDE (Intelij) says there is a required field on the SimplePager, but strangely it compiles and runs without problem. I think its strange that you can do pager = new SimplePager(); <-- not calling the constructor which specifies TextLocation or setting it, yet the SimplePager ui tag fails. This has to be a bug doesnt it, z00bs?Antinomian
E
1

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);
}
Exanimate answered 1/5, 2014 at 20:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.