2

I am usign GWT2.3. We developed CustomPager by overriding SimplePager.

We override createText() method such a way that we are showing string like "Page 1 of 4" using following code

    public String createText() {
        if(searchRecordCount%pageSizeForText == 0){
            totalPages = searchRecordCount/pageSizeForText;
        }else{
            totalPages = (searchRecordCount/pageSizeForText) + 1;
        }
        NumberFormat formatter = NumberFormat.getFormat("#,###");
        return "Page "+formatter.format(this.getPage()+1) + " of " + formatter.format(totalPages);
      }

enter image description here

Now I want to use TextBox for CurrentPage so that user can enter page Number in textBox. (Functionality GoTo entered pageNumber)

createText() returns string so I cant user textBox ;) + Can't provide css

How can I do this ? Is there any way to solve this problem? Workaround if any or Sample code

StackOverFlow
  • 4,486
  • 12
  • 52
  • 87

1 Answers1

3

There are two ways how to achieve this:

1.) Use HTML code to create a TextBox:

In the createText() function you can create the textbox manually by using HTML code (better use SafeHTML templates for avoiding XSS):

String textbox_str = "<input type='textbox' name='goto'>";

However you have to write code for handling the actual event (i.e. ChangeEvent) and call setPage() of your SimplePager using JSNI.

2.) Add TextBox widget to SimplePager and override constructor:

SimplePager is basically a Composite which adds ImageButtons in its constructor for the forward and backward links.
You can extend SimplePager add a TextBox and override the constructor to add the TextBox between the forward and backward ImageButtons.

Ümit
  • 17,379
  • 7
  • 55
  • 74
  • Thanks for reply. In #1 answer: How n where to add SafeHtmlTemplates in createText() ? – StackOverFlow Dec 13 '11 at 06:15
  • Use either ``SaveHTMLBuilder`` or a ``SaveHTMLTemplate``. See [here](http://code.google.com/webtoolkit/doc/latest/DevGuideSecuritySafeHtml.html#Creating_SafeHtml_Values) fore more details. – Ümit Dec 13 '11 at 10:20
  • createText() method called from onRangeOrRowCountChanged() and output of createText() set as string not html in SimplePager.java :( i.e. html_label.setText(createText()); There should be htmlLabel.setHtml("...html or string.") – StackOverFlow Dec 13 '11 at 12:57
  • How to add a textbox between the forward and backward buttons. – Bennet Dec 09 '13 at 09:02
  • `panel.add(new TextBox())` with panel being a `FlowPanel` for example. – Ümit Dec 09 '13 at 10:12
  • will that add the textbox in between forward and backward image buttons? – Bennet Dec 09 '13 at 21:17
  • 1
    Your second suggestions works like a charm. Overrode `onLoad` instead and added my `TextBox` using `((HorizontalPanel) getWidget()).insert(textBox, 2)` to make it appear in the middle (assuming that you use 4 buttons). – Baz Feb 25 '14 at 10:25