-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi
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.
Thx for help me
Best
Hi,
you can use a Toolbarbutton (or any other button like the A-Tag) in the following way:
Toolbarbutton tb = new Toolbarbutton("Click me"); tb.setHref("http://www.zkoss.org/"); tb.setTarget("_blank");
HTH, Maik
But in my example is not possible to use your code because I create the the toolbarbuttons inside a grid dinamically
I also tried to use the code bellow but doesn't work neither
java.lang.Boolean cannot be cast to org.zkoss.zk.ui.Component
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())
.addEventListener(Events.ON_CLICK, new EventListener() {
public void onEvent(Event evt) {
Executions.getCurrent().sendRedirect(app.getEnvApp(), "_blank");
Executions.getCurrent().sendRedirect(self.getAttribute("label").toString(), "_blank");
}
})
);
I got a error message:
java.lang.Boolean cannot be cast to org.zkoss.zk.ui.Component
Some other way?
Hi,
why can't you use it in the following way?
public void render(Row row, Object data) throws Exception { 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); } });
Cheers, Maik
Hi Maik,
Could you provide me the steps to open the window with external url. When i use the below onclick method it is opening in new tab, but i am expecting it to be open in a window like popup. onClick='execution.sendRedirect("http://zkoss.org", "_blank")'
Opening a popup window requires some JS code so a client side widget-event listener w:onClick
should do that (provided the user's browser(/settings) allow that):
<zk xmlns:w="client">
...
<button label="open example.org in a popup"
w:onClick="window.open('http://www.example.org/', '_blank', 'scrollbars');"/>
...
</zk>
The equivalent java code is:
button.setWidgetListener("onClick", "window.open('http://www.example.org/', '_blank', 'scrollbars');");
One might be tempted to trigger the JS from the server side directly via Clients.evalJavaScript(...)
however browsers will consider this an untrusted event and block the popup under most conditions - Especially when external URLs are opened.
It seems your first sentence was truncated somehow. Please post again and make sure nothing is missing.
Hi Maik,
Am trying to call below javascript method from Clients.evalJavaScript() and its not executing. Could you please provide the steps to load the javascript and execute it by using the Clients. Is there any way get the return value.
function getData() { var url="";//external site url newwindow=window.open(url,'name','height=200,width=150'); if (window.focus) {newwindow.focus()} return false; }
As I explained before, trying to open a POPUP from an AJAX response (which is a ZK server side listener) will run into the browsers built in popup blocker. Because a server side response is not a trusted event. (please read on un/trusted events) the whole advertisement branche broke the web with unsolicited popups which are now commonly blocked by browsers. However a direct listener to an onClick listener AT CLIENT side creates a trusted event which allows you to open a Popup.
Here a zkfiddle showing the difference between a client side and server side listener. In both cases the JS is executed. When getData() is called from the server side event listener the browser will prevent the Popup unless you change your popup settings. Chrome will just ignore the popup whild FF will inform you about the blocked popup.
http://zkfiddle.org/sample/323lscb/1-compare-popup-from-client-or-server
So you CAN NOT use Clients.evalJavaScript to open a popup, only a browser tab. You have to add custom client side event listener.
Asked: 2011-04-29 14:06:33 +0800
Seen: 895 times
Last updated: Nov 13 '18