Bera
Bera

Reputation: 1282

Open url inside a grid in a new browser window

I have a list of urls in a grid, And I need that when a user click in a url a new browser windows open with the same url

I read some threads but in my case I believe my situation is a little different. In my controller I'm using the following code

UrlListCollection.generateListUrl();

dataGrid.setRowRenderer(new RowRenderer() { 
    public void render(Row row, Object data) throws Exception {
        UrlObj url = (UrlObj) data;
            row.getChildren().add(new Label("Some data"));          
            row.getChildren().add(new Toolbarbutton(url.getUrlApp()));   //  url.getUrlApp() will be return a link like  http://www.google.com
        }
    });

In my view(zul) I have

<grid id="dataGrid" width="100%">
    <columns>
        <column label="Some Data" sort="auto(FIELD_NAME)" width="200px" />
        <column label="URL LINK" sort="auto(URL)" width="630px" />
    </columns>
</grid> 

But the common way to set an event an component in java can be:

Toolbarbutton button = new Toolbarbutton(url.getUrlApp()));
  button.addEventListener(Events.ON_CLICK, new EventListener() {
      public void onEvent(evt) {

          // what I put here to open a Link in another web browser window  ????
      // and I need to be able to open every object value retrieved by url.getUrlApp()   ???
      }
  });

I don't now what is necessary to make my code works..for me the way to apply a Event to toolbar button inside a grid that use RowRenderer method is strange. I can't see a solution by myself.

Upvotes: 0

Views: 3506

Answers (2)

jumperchen
jumperchen

Reputation: 1473

You can use the following example,

Executions.getCurrent().sendRedirect("http://www.google.com", "_blank");

Or you may use the A component with the setHref() method instead of the Toolbarbutton component.

Upvotes: 2

Bera
Bera

Reputation: 1282

This works fine for me, thanks!

  UrlObj url = (UrlObj) data;

  Toolbarbutton tb = new Toolbarbutton(url.getUrlApp());
  tb.setHref(url.getUrlApp());
  tb.setTarget("_blank");

  row.getChildren().add(new Label("Some data"));
  row.getChildren().add(tb);

Upvotes: 0

Related Questions