2

我正在使用 GWT2.3。我们通过覆盖 SimplePager 开发了 CustomPager。

我们覆盖 createText() 方法,使用以下代码显示类似“Page 1 of 4”的字符串

    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);
      }

在此处输入图像描述

现在我想为 CurrentPage 使用 TextBox,以便用户可以在 textBox 中输入页码。(功能GoTo输入的pageNumber)

createText() 返回字符串,所以我不能使用 textBox ;) + 不能提供 css

我怎样才能做到这一点 ?有没有办法解决这个问题?解决方法(如果有)或示例代码

4

1 回答 1

3

有两种方法可以实现这一点:

1.)使用 HTML 代码创建一个 TextBox

createText()函数中,您可以使用 HTML 代码手动创建文本框(最好使用SafeHTML 模板来避免 XSS):

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

但是,您必须编写代码来处理实际事件(即 ChangeEvent)并setPage()使用 JSNI 调用 SimplePager。

2.)将 TextBox 小部件添加到 SimplePager 并覆盖构造函数

SimplePager基本上是一个 Composite,它在其构造函数中为前向和后向链接添加 ImageButtons。
您可以扩展 SimplePager 添加一个 TextBox 并覆盖构造函数以在前进和后退 ImageButtons 之间添加 TextBox。

于 2011-12-12T15:10:31.667 回答