Table row onClick Window.location??

883 views
Skip to first unread message

bfk...@gmail.com

unread,
Oct 9, 2006, 10:39:05 AM10/9/06
to Google Web Toolkit
Hi All,

I have a page where I have a flex table and a couple of rows.
I've added a onClcik event, and want that a variable which is available
to me is used as a link to open the url in the same window (not
Window.open("", "", "") as this opens a new window).

For example:

public void onCellClicked(SourcesTableEvents sender, int row, int cell)
{
// Select the row that was clicked (-1 to account for header row).
if (row > 0)
selectRow(row - 1);
}

private void selectRow(int row) {
// When a row (other than the first one, which is used as a header)
is
// selected, display its associated MailItem.
MailItem item = MailItems.getMailItem(startIndex + row);
if (item == null)
return;

Window.alert(item.url);
//External Link here
}

Basically, the URL does show in the alert. But how can I do something
like:

Window.location= item.url;
Where I keep the same window and do not open a new one?
Using Window.open just opens a new window...


A basic html page to explain what I mean about keeping it in the same
window:
<html>
<head></head>
<body>

<img src="http://www.google.com/images/logo_sm.gif"
onclick="window.location.href='http://www.google.com'">

</body>
</html>


Thank you for your time.
Much appreciated,

mP

unread,
Oct 9, 2006, 10:34:28 PM10/9/06
to Google Web Toolkit
Msot of the time this should not be attempetd because Javascript in
general does not support sandboxing of the child window... such as what
is found in Frames. There is nothing to stop a child taking over the
browser and making it the main frame and so on.

bfk...@gmail.com

unread,
Oct 10, 2006, 3:55:42 AM10/10/06
to Google Web Toolkit
Hi,

thank your for your input, I see the dilema.
However, I fully expect the window to visit another location and
completely leave my gwt site. That is the desired effect. I don't want
to have a table with text that you have to click like a simple <a
href>, but instead make the whole row into a link.
This can be achieved using:

<table width=100% border=1>
<tr>
<td>Hello</td>
</tr>
<tr onClick="window.location.href='http://www.google.com'">
<td>Goodbye</td>
</tr>
</table>

Is there an easy way to set the properties of a table row?
Even if there is, I'd still have to find a way to navigate the current
page away from it's current URL without opening a new window.

Perhaps I'm asking too much, and you shouldn't be able to do this, but
I don't really see why not =)

Thanks again for your help. I really appreciate it.
Best regards,

peterrosconi

unread,
Oct 10, 2006, 11:02:25 AM10/10/06
to Google Web Toolkit
I couldn't find a redirect or setLocation() method in the JavaDocs, so
I assume it is not there. However, I came up with a solution for at
least the image example:

...
Image img = new Image("http://www.google.com/images/logo_sm.gif");
DOM.setStyleAttribute(img.getElement(), "cursor", "pointer");
img.addClickListener(new ClickListener()
{
public void onClick(Widget sender)
{
setLocation("http://www.google.com/");
}
});
RootPanel.get().add(img);
...

/**
* Sets the window.location.href to the specified url; thus
redirecting
* to said url.
*
* @param url The url to redirect to.
*/
public native void setLocation(String url) /*-{

$wnd.location.href = url;

}-*/;

...

bfk...@gmail.com

unread,
Oct 11, 2006, 3:27:24 AM10/11/06
to Google Web Toolkit
Aha! I see.

Just one silly question though =) (theres always one):

What is $wnd? I certainly can't do Window.location.href, so in this
example, what does the $wnd reference?

Thanks for all the help.
Best regards,

Reply all
Reply to author
Forward
0 new messages