2011-12-23 110 views
1

我有一个单元格的GWT与textcells和buttoncell,现在我想添加一个超链接单元格在我的celltable中,这可能吗?GWT中的超链接单元格CellTable

    TextCell jobStatusCell = new TextCell(); 
    jobStatusColumn = new Column<EmployerJobs, String>(jobStatusCell) { 
     @Override 
     public String getValue(EmployerJobs object) { 

      // int status = object.getJobStatusId(); 
      /* 
      * if(status ==1) { return ""; } else 
      */ 
      // return "post job"; 
      return "view"; 
     } 
    }; 

我想一些这样的事

   HyperlinkCell jobStatusCell = new HyperLinkCell(); 

感谢

回答

1

你的意思是这个HyperlinkCell

如果不是,您可以编写一个普通超链接(<a href="http://www.stackoverflow.com">linkCell </a>)并将其作为单元格的内容。

+0

是超链接单元仍然是一个东西吗?你的链接把我带到别处。 – 2016-07-29 14:48:21

+0

@StealthRabbi提问者从未确认他所指的是哪个HyperlinkCell。 GWT从来没有提供一个所以我只是GOOGLE和第一个。但是,我不确定这是他使用的那个 – 2016-07-30 18:14:15

+0

尽管如此,你在答案中的链接并没有把我带到一个叫HyperlinkCell的类。至少,我无法在源代码链接中找到它。 – 2016-08-01 11:51:16

0

尝试使用以下单元实现

要确保你提供单元格的值像2个String对象的数组:

String[] value = new String[2]; 
value[HyperTextCell.LINK_INDEX] = "http://www.google.com"; 
value[HyperTextCell.TEXT_INDEX] = "Search on google"; 

public class HyperTextCell extends AbstractCell<String[]> { 

interface Template extends SafeHtmlTemplates { 
    @Template("<a target=\"_blank\" href=\"{0}\">{1}</a>") 
    SafeHtml hyperText(SafeUri link, String text); 
} 

private static Template template; 

public static final int LINK_INDEX = 0, URL_INDEX = 1; 

/** 
* Construct a new ImageCell. 
*/ 
public HyperTextCell() { 

    if (template == null) { 
     template = GWT.create(Template.class); 
    } 
} 

@Override 
public void render(Context context, String[] value, SafeHtmlBuilder sb) { 
    if (value != null) { 

     // The template will sanitize the URI. 
     sb.append(template.hyperText(UriUtils.fromString(value[LINK_INDEX]), value[URL_INDEX])); 
    } 
    } 
}