Is it a bug?

68 views
Skip to first unread message

Sundraw

unread,
Jun 15, 2006, 7:50:39 AM6/15/06
to Google Web Toolkit
I am trying to print the contents of a page from GWT code. This is
easy:

public native void printFrame() /*-{
$wnd.print();
}-*/;

But this prints the whole page, and I want to print the contents of one
of iframes only. So before printing I am setting focus on the iframe I
want to print, and then I am calling the above function, like this:

frmDiaInfo.setFocus(true);
printFrame();

But this causes the following exception:

com.google.gwt.core.client.JavaScriptException: JavaScript TypeError
exception: elem.focus is not a function

Is this a bug?

Eugine

unread,
Jun 15, 2006, 10:29:26 AM6/15/06
to Google Web Toolkit
In my experience, in order to print any Widget's content (including the
content of any panel) it's easiest to do
"System.out.println(myWidget.getElement());"

Hope this helps.

Sundraw

unread,
Jun 15, 2006, 10:53:47 AM6/15/06
to Google Web Toolkit
Thank you, Eugine,

But what I wanted to achieve is to make browser open a standard print
dialog - which would be normally achieved in ordinary JavaScript by
using window.print() function.

I was experimenting for a while with JavaScript in a native method and
the results are strange. Say, I want to check whether the standard
window object which is referred to in GWT as $wnd knows anything about
my iframes at all. I have used the following code:

var x = $wnd.frames;
$wnd.alert(x.length);

Which informs me that $wnd has 3 frames. I don't use any frames on that
page, but I use 2 iframes, and the third may be added by GWT itself.
Fine.

But now I am trying to find out some information about those iframes,
like so:

var x = $wnd.frames[1].name - produces an empty string perhaps, the
alert box is empty
var x = $wnd.frames[1].id and the same for src produces 'undefined'.

Attempts like

$wnd.frames[1].focus();
$wnd.frames[1].print();

or

$wnd.frames[1].focus();
$wnd.print();

also do not produce the desired effect.

I have no way to assign any name to the Frame widget. I do not see how
I could print it contents using the standard browser (and OS)
facilities - something I would be able to do in basic JavaScript. So
far my conclusion is that GWT is too young at the moment.

glongman

unread,
Jun 15, 2006, 11:06:44 AM6/15/06
to Google Web Toolkit
You are reporting a shortcoming in one widget and based on that you
make a general statement about the entire framework? I'm tired of
people finding a problem and when they don't get the response they want
they come back with a blanket statement which borders on the edge of
being flamebait.

Of course the framework is too young, many requests have been made to
improve it already. It's been out for what, 3 weeks?

Perhaps if you phrased this as a feature request (which is what this
is) and proposed a patch you will get some movement and ultimately
satisfaction.

Geoff

Sundraw

unread,
Jun 15, 2006, 11:16:55 AM6/15/06
to Google Web Toolkit
Uff, Geoff, you are so passionate! :)

And of course you are right. GWT is fascinating, and it only the lack
of knowledge of how to communicate a feature request makes me producing
this kind of statements.

Thanks for the Spindle, by the way!

Scott Blum

unread,
Jun 15, 2006, 11:41:04 AM6/15/06
to Google Web Toolkit
Hi Sundraw,

It's possible that not all browsers allow IFrames to receive focus.
We'll take a look at this. Meanwhile, do you need to focus the IFrame
to print it? You might try this:

private native void printFrame(Element e) /*-{
e.contentWindow.print();
}-*/;

printFrame(frmDialInfo.getElement());

Scott

glongman

unread,
Jun 15, 2006, 11:50:18 AM6/15/06
to Google Web Toolkit
A little hard on you, sorry. Perhaps this thread has gone far enough to
identify that a RFE is needed and should be put to bed and new one
started with [FEATURE REQUEST] prepended to the subject. With a link to
this thread of course.

And thanks for the compliment!

Geoff

Sundraw

unread,
Jun 15, 2006, 12:31:01 PM6/15/06
to Google Web Toolkit

> private native void printFrame(Element e) /*-{
> e.contentWindow.print();
> }-*/;
>
> printFrame(frmDialInfo.getElement());
>

This works like magic with Firefox, but IE6 still prints the whole
page...

Thanks a lot for your help guys!

Alex

Reply all
Reply to author
Forward
0 new messages