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?

rapadura
  • 5,242
  • 7
  • 39
  • 57

3 Answers3

24

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

<c:SimplePager ui:field='pager' location='CENTER'/>
Peter Knego
  • 79,991
  • 11
  • 123
  • 154
  • 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. – rapadura Nov 28 '10 at 11:48
  • I got this error if I add the location attribute : [ERROR] Class SimplePager has no appropriate setLocation() method Element (:12) – tbruyelle Oct 30 '11 at 11:22
  • 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. – Johan S Jun 29 '12 at 10:43
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");
    }
}
z00bs
  • 7,518
  • 4
  • 34
  • 53
  • 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? – rapadura Nov 28 '10 at 11:51
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);
}
Timothy Gonzalez
  • 1,802
  • 21
  • 18