Hyperlinks to external website

Hi,
I have a column in database where i have stored all the URL’s in it. now, when I display them in the table it is showing as text. I wanted it to be shown as Hyperlink and when the user clicks on it, the external URL should be opened. Please can you help me out.

Thanks,
Dhanush.

1 Like

Hi,

You can create a generated column with the Link component, for example:

customersTable.addGeneratedColumn("email", entity -> {
    Link link = componentsFactory.createComponent(Link.class);
    link.setCaption(entity.getEmail());
    link.setUrl("mailto:" + entity.getEmail());
    link.setTarget("_blank");
    return link;
});

Regards,
Gleb

Hey @gorelov,

Thanks for the it. It working but i’m getting a exception as " RuntimeException: Source must be non-null".
In my database , there are URL’s for some fields and null values for some fields.
When I’m open this screen its poping out this exception.
even if i’m trying to sort the fields by the GroupTable header it is showing the same Exception.
Can you please find out it. The following is the code:

public void init(Map<String, Object> params){
md_ProductsesTable.addGeneratedColumn("pvsPublication", entity -> {
                    Link link = componentsFactory.createComponent(Link.class);
                    link.setCaption("Click Here");
                    link.setUrl(entity.getPvsPublication());
                    link.setTarget("_blank");
                    return link;
                });
}

public Component generateTable(Md_Products entity) {
return new Table.PlainTextCell(entity.getPvsPublication());
}

in XML:

      <groupTable id="md_ProductsesTable"
                width="100%">
           <column id="pvsPublication"
                    caption="FIELD TRIAL DATA"
                    generator="generateTable"/>

Here is the stack trace:

java.lang.RuntimeException: Source must be non-null
	at com.vaadin.server.ExternalResource.<init>(ExternalResource.java:80)
	at com.haulmont.cuba.web.gui.components.WebLink.setUrl(WebLink.java:32)
	at com.keansa.keansacloud.web.md_products.Md_ProductsBrowse.lambda$init$3(Md_ProductsBrowse.java:126)
	at com.haulmont.cuba.web.gui.components.WebAbstractTable$6.generateCell(WebAbstractTable.java:1622)
	at com.vaadin.ui.Table.parseItemIdToCells(Table.java:2410)
	at com.vaadin.ui.Table.getVisibleCellsNoCache(Table.java:2282)
	at com.vaadin.ui.Table.refreshRenderedCells(Table.java:1780)
	at com.vaadin.ui.Table.enableContentRefreshing(Table.java:3336)
	at com.vaadin.ui.Table.changeVariables(Table.java:3168)
	at com.haulmont.cuba.web.toolkit.ui.CubaTable.changeVariables(CubaTable.java:252)
	at com.haulmont.cuba.web.toolkit.ui.CubaGroupTable.changeVariables(CubaGroupTable.java:144)
	at com.vaadin.server.communication.ServerRpcHandler.changeVariables(ServerRpcHandler.java:623)
	at com.vaadin.server.communication.ServerRpcHandler.handleInvocation(ServerRpcHandler.java:470)
	at com.vaadin.server.communication.ServerRpcHandler.handleInvocations(ServerRpcHandler.java:413)
	at com.vaadin.server.communication.ServerRpcHandler.handleRpc(ServerRpcHandler.java:274)
	at com.vaadin.server.communication.UidlRequestHandler.synchronizedHandleRequest(UidlRequestHandler.java:90)
	at com.vaadin.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:41)
	at com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1422)
	at com.vaadin.server.VaadinServlet.service(VaadinServlet.java:385)
	at com.haulmont.cuba.web.sys.CubaApplicationServlet.serviceAppRequest(CubaApplicationServlet.java:290)
	at com.haulmont.cuba.web.sys.CubaApplicationServlet.service(CubaApplicationServlet.java:197)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
	at com.haulmont.cuba.web.sys.CubaHttpFilter.handleNotFiltered(CubaHttpFilter.java:108)
	at com.haulmont.cuba.web.sys.CubaHttpFilter.doFilter(CubaHttpFilter.java:95)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:474)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
	at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:624)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349)
	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:783)
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:789)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1437)
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:748)

image

Even the Tab name has been disappered.
image

The url attribute cannot be null, so do not create a link if the corresponding entity value is null.

Regards,
Gleb