试图在我的GWT cellTable中添加一些链接单元格

时间:2012-02-09 14:31:41

标签: gwt

我正在尝试在我的单元格表中添加一个链接(我只想让项目加下划线并在悬停时更改鼠标符号)

点击后我只想给一个窗口提醒。

因为我尝试了这些选项:(但没有运气)

1)

           final Hyperlink hyp  = new Hyperlink("test", "test");


    Column<EmployerJobs, Hyperlink> test = new Column<EmployerJobs, Hyperlink>(new HyperLinkCell())

    {
        @Override
        public Hyperlink getValue(EmployerJobs object)
        {
        return hyp;
        }
    };

选项1的问题是,它需要我导航页面“测试”,而我不想去任何其他页面我只想要一个窗口警报。

2)

         Column<EmployerJobs, SafeHtml> test = new Column<EmployerJobs, SafeHtml>(new SafeHtmlCell())
    {
        @Override
        public SafeHtml getValue(EmployerJobs object)
        {
            SafeHtmlBuilder sb = new SafeHtmlBuilder();
            sb.appendEscaped("test");

                return sb.toSafeHtml();
        }
    }; 

选项2的问题是我不知道究竟要返回这里并且没有加下划线。

3)最后我试图用复合单元格在我的单元格中添加锚点(理想情况下,我希望在我的单元格中有三个不同的锚点)

final Anchor anc = new Anchor();
    ArrayList list = new ArrayList();
    list.add(anc);
     CompositeCell ancCell = new CompositeCell(list);
    Column testColumn1 = new Column<EmployerJobs, Anchor>(ancCell) {

        @Override
        public Anchor getValue(EmployerJobs object) {


            return anc;
        }       
    };

选项3给出了一些例外。

如果你能帮助我开始上述任何一种选择,我将不胜感激

谢谢

1 个答案:

答案 0 :(得分:3)

你这样做完全错了。你需要使用ActionCell这样的东西或创建自己的单元格。示例代码:

    ActionCell.Delegate<String> delegate = new ActionCell.Delegate<String>(){ 
      public void execute(String value) { //this method will be executed as soon as someone clicks the cell
              Window.alert(value);

      } 
    };
    ActionCell<String> cell = new ActionCell<String>(safeHtmlTitle,delegate){

        @Override
        public void render(com.google.gwt.cell.client.Cell.Context context,  //we need to render link instead of default button
                String value, SafeHtmlBuilder sb) {
            sb.appendHtmlConstant("<a href='#'>");
            sb.appendEscaped(value);
            sb.appendHtmlConstant("</a>");
        }
    }; 

    Column testColumn1 = new Column<EmployerJobs, String>(cell) {

        @Override
        public String getValue(EmployerJobs object) { 
            //we have to return a value which will be passed into the actioncell

            return object.name;
        }       
    };

我建议您阅读Cell Widgets的官方documentation,因为它几乎是您需要了解的有关单元格小部件的所有内容。