Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding Hyperlink in GWT celltable

Tags:

gwt

I am trying to add a hyperlink in celltable and on clicking on that link i want to call a method.

with the below code i am getting a hyperlink in my celltable correctly but I am not able to call a method by clicking on the link , when i click the link it takes me to the previous page.

Any Solution

Hyperlink link = new Hyperlink("Delete","");

Column<EmployerJobs, Hyperlink> linkColumn = 
    new Column<EmployerJobs, Hyperlink>(new HyperLinkCell()) { 
      @Override 
      public Hyperlink getValue(EmployerJobs list) {
        link.addClickHandler(new ClickHandler() {
          public void onClick(ClickEvent event) {
            deleteJobs(list);
          }
        });
        return link; 
      }
});
like image 304
junaidp Avatar asked Jul 12 '26 10:07

junaidp


1 Answers

Instead of a HyperlinkCell you can either use a ClickableTextCell, a ButtonCell or an ActionCell.

ClickableTextCell:

Column<EmployerJobs, String> linkColumn = 
    new Column<EmployerJobs, String>(new ClickableTextCell())  {
         @Override
         public String getValue(EmployerJobs object)  {
             return TEXT_TO_DISPLAY;
         }
    },'linkheadertext');
linkColumn.setFieldUpdater(new FieldUpdater<EmployerJobs, String>() {
         @Override
         public void update(int index, EmployerJobs object, String value) {
             deleteJobs(object);
         }
});

ButtonCell:

Column<EmployerJobs, String> buttonColumn = 
    new Column<EmployerJobs, String>(new ButtonCell())  {
         @Override
         public String getValue(EmployerJobs object)  {
             return TEXT_TO_DISPLAY;
         }
    },'linkheadertext');
buttonColumn.setFieldUpdater(new FieldUpdater<EmployerJobs, String>() {
         @Override
         public void update(int index, EmployerJobs object, String value) {
             deleteJobs(object);
         }
});

ActionCell:

Column<EmployerJobs, EmployerJobs> actionColumn = 
    new Column<EmployerJobs, EmployerJobs>(new ActionCell<EmployerJobs>("Click Me",
        new ActionCell.Delegate<EmployerJobs>() {
            @Override
            public void execute(EmployerJobs jobs) {
                deleteJobs(jobs);
            }
        })
    {
         @Override
         public EmployerJobs getValue(EmployerJobs object)  {
             return object;
         }
    },'linkheadertext');

Check out the CellSample showcase for more infos.

like image 115
Ümit Avatar answered Jul 14 '26 18:07

Ümit



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!