2015-03-13 29 views
2

我是vaadin的新手,我想将数据库中的vaadin表列作为超链接。我试着用这段代码。在这里,我在代码中使用PagedTable而不是普通的vaadin表。我尝试了所有可能的方式,但我没有得到结果。做出超链接后,如果用户单击该链接,我需要显示POPUP窗口。从数据库中创建表列作为vaadin中的超链接

 if (rs.next()) { 
     Object dashboardDataRowId = _reportTable.addItem(); 

        Link l = new Link("rs.getInt(1)", new ExternalResource(
          "#")); 

        _reportTable.getItem(dashboardDataRowId) 
          .getItemProperty("todo").setValue(l); 
        _reportTable.getItem(dashboardDataRowId) 
          .getItemProperty("watchlist") 
          .setValue(rs.getInt(2)); 
        _reportTable.getItem(dashboardDataRowId) 
          .getItemProperty("terminated") 
          .setValue(rs.getInt(3)); 
        _reportTable.getItem(dashboardDataRowId) 
          .getItemProperty("processed") 
          .setValue(rs.getInt(4)); 
        _reportTable.getItem(dashboardDataRowId) 
          .getItemProperty("total") 
          .setValue(rs.getInt(5)); 

       } 
      } catch (Exception e) { 
       logger.error(
         "Error loading dashboard report. Exception: {}", 
         e.getMessage()); 
       logger.debug("Error loading dashboard report.", e); 
       showWarningNotification(
         "Error loading dashboard report. Please contact admin", 
         "Error message is " + e.getMessage()); 

      } finally { 
       rs.close(); 
       stmt.close(); 
      } 

     } 
    }); 

} 

private void populateReportTableColumns(final PagedTable reportTable) { 

    reportTable.addContainerProperty("todo", Link.class, "-", "To Do", 
      null, null); 

    // reportTable.addContainerProperty("watchlist", Link.class, new 
    // Link("Watch List", new ExternalResource("#")), "Watch List", null, 
    // null); 
    reportTable.addContainerProperty("watchlist", Button.class, "-", 
      "Watch List", null, null); 
    reportTable.addContainerProperty("terminated", Button.class, "-", 
      "Terminated", null, null); 
    reportTable.addContainerProperty("processed", Button.class, "-", 
      "Processed and Closed", null, null); 
    reportTable.addContainerProperty("total", Button.class, "-", "Total", 
      null, null); 
} 

回答

3

我明白了。

Link link = new Link(String.valueOf(rs.getInt(1)), new ExternalResource("#")); 
    _reportTable.getItem(dashboardDataRowId) 
    .getItemProperty("todo").setValue(link); 

现在链接来了,但我需要显示弹出当用户点击链接。

1

您可以使用生成的列完成此操作。

,而不是添加链接对象作为项目的属性值,你只需设置的网址:

_reportTable.getItem(dashboardDataRowId).getItemProperty("todo").setValue("http://vaadin.com"); 

而且有行产生从URL创建链接对象:

reportTable.addGeneratedColumn("link", new Table.ColumnGenerator() { 

      @Override 
      public Object generateCell(Table source, Object itemId, Object columnId) { 
       String url = (String) source.getItem(itemId).getItemProperty("todo").getValue(); 
       return new Link("LinkTitle", new ExternalResource(url)); 
      } 
     }); 

这是未经测试的代码,但通常它应该像这样工作。

编辑: 在Vaadin的新窗口中打开链接的大多数方法是使用BrowserWindowOpener。你需要使用一个按钮,而不是一个链接,但如果你希望它仍然看起来是一样的,你可以风格的按钮,看起来像一个链接:

Button link = new Button(); 
link.setStyleName(Runo.BUTTON_LINK); // use the theme you are currently extending here 
BrowserWindowOpener opener = new BrowserWindowOpener(new ExternalResource("http://vaadin.com")); 
opener.extend(link); 

另外,您可以链接目标设置为_blank但大多数浏览器在新窗口中打开此窗口而不是窗口:

link.setTargetName("_blank"); 
+0

谢谢。但是当用户点击链接时,我需要显示弹出窗口。 – mchinta 2015-03-14 06:31:12

+0

如何在用户点击vaadin中的链接时启用弹出窗口。 – mchinta 2015-03-14 06:34:09

相关问题