Usage of WAIframeTag

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Usage of WAIframeTag

Martin J. Laubach-2
  After rummaging through the docs and google, I give up and
yell for help: How does one actually use the WAIframeTag?

  I want to have something like this:

        content := #[ "ByteArray that really is a PDF" ].
        html iframe contents: content.

   however, that gives me a HTML page with the content as string
representation -- not quite what I had in mind. So, how does one

   * correctly use the canvas iframe to serve out some random
     byte stream?
   * set the Content-Type for that stream
   * (would be nice) generate an URL that will be cached by the
     browser. Is this even possible?

  Regards,

        mjl



_______________________________________________
Seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Usage of WAIframeTag

Lukas Renggli
>   I want to have something like this:
>
>         content := #[ "ByteArray that really is a PDF" ].
>         html iframe contents: content.
>
>    however, that gives me a HTML page with the content as string
> representation -- not quite what I had in mind. So, how does one
>
>    * correctly use the canvas iframe to serve out some random
>      byte stream?
>    * set the Content-Type for that stream
>    * (would be nice) generate an URL that will be cached by the
>      browser. Is this even possible?

Sure, everything is possible.

#contents: should be used with a render block, it is basically what
you would expect when sending #with: to the tag. Though, and this is a
technical detail, the IFRAME requires that you provide the contents as
a separate file, therefor I needed to use a different selector and
setup a separate render in there. Have a look at the senders of
#iframe, especially the test in WAIframeTest.

Though #contents: is not what you want, and in fact serving documents
through an IFRAME is not implemented yes. So lets just do it by
implementing the full method and then add two convenience methods:

WAIframeTag>>document: anObject mimeType: aMimeString fileName: aFileNameString
        self src: (canvas context
                urlForDocument: anObject
                mimeType: aMimeString
                fileName: aFileNameString)

WAIframeTag>>document: anObject mimeType: aMimeString
        self document: anObject mimeType: aMimeString fileName: nil

WAIframeTag>>document: anObject
        self document: anObject mimeType: nil

This code is included in the latest Squeak version of Seaside. Add the
by yourself, if you are on VisualWorks. I also updated the test.

Hope this helps,
Lukas

--
Lukas Renggli
http://www.lukas-renggli.ch
_______________________________________________
Seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Usage of WAIframeTag

Martin J. Laubach-2
|  WAIframeTag>>document: anObject mimeType: aMimeString fileName: aFileNameString
|   self src: (canvas context
|   urlForDocument: anObject
|   mimeType: aMimeString
|   fileName: aFileNameString)

  Thanks a lot, that works great!

  I arrived at the code below after much trial and error (and I'm
not sure I know what it does) -- it works but it's very different
to your solution (and more complicated to boot). What does it actually
do at all/differently/wrong? Was that the completely wrong way to attack
the problem?

WAIframeTag>>document: anObject mimeType: aMimeString fileName: aFileNameString
        | key |
        key := html callbacks registerActionCallback:
                [self session
                        returnResponse: (Seaside.WADocumentHandler
                                        document: anObject
                                        mimeType: aMimeString
                                        fileName: aFileNameString) response].
        self src: (html context actionUrl withParameter: key) asString



  Regards

        mjl
_______________________________________________
Seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Re: Usage of WAIframeTag

Lukas Renggli
>   I arrived at the code below after much trial and error (and I'm
> not sure I know what it does) -- it works but it's very different
> to your solution (and more complicated to boot). What does it actually
> do at all/differently/wrong? Was that the completely wrong way to attack
> the problem?
>
> WAIframeTag>>document: anObject mimeType: aMimeString fileName: aFileNameString
>         | key |
>         key := html callbacks registerActionCallback:
>                 [self session
>                         returnResponse: (Seaside.WADocumentHandler
>                                         document: anObject
>                                         mimeType: aMimeString
>                                         fileName: aFileNameString) response].
>         self src: (html context actionUrl withParameter: key) asString

As you observed, your code doesn't do exactly the same thing. You are
registering a new callback every time the page is rendered, therefor
the link changes and cannot be cached by the browser. Actually this is
a good technique, say if you generate your PDF dynamically and only
want to build it (within the callback) when it is actually accessed.

My solutions creates a document handler with a unique URL that won't
change as long as your document doesn't change. The document will be
downloaded by the browser only once and then put into its cache. If I
am not completely mistaken, the document handler will be part of the
application, so it is shared among all sessions.

Cheers,
Lukas

--
Lukas Renggli
http://www.lukas-renggli.ch
_______________________________________________
Seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Usage of WAIframeTag

Martin J. Laubach-2
In reply to this post by Lukas Renggli
|  WAIframeTag>>document: anObject mimeType: aMimeString fileName: aFileNameString
|   self src: (canvas context
|   urlForDocument: anObject
|   mimeType: aMimeString
|   fileName: aFileNameString)

  This works perfectly to serve out random binary stream. Now how
long will such a link work? I'll be serving out potentially large
documents, ie. if the answer is "forever", that will clutter my
image with multi-megabytes of old document data.

  I guess something like

        ... canvas context urlForBlock: [ "fetch data stream" ] ...

  would solve that concern quite nicely, but is there something
like that? Browsing WADocumentHandler, it doesn't seem all that
difficult to add, does it?

        mjl
_______________________________________________
Seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Re: Usage of WAIframeTag

Lukas Renggli
>   This works perfectly to serve out random binary stream. Now how
> long will such a link work? I'll be serving out potentially large
> documents, ie. if the answer is "forever", that will clutter my
> image with multi-megabytes of old document data.

Yes, as far as I know forever. This is not suggested for dynamic content then.

>   I guess something like
>
>         ... canvas context urlForBlock: [ "fetch data stream" ] ...
>
>   would solve that concern quite nicely, but is there something
> like that? Browsing WADocumentHandler, it doesn't seem all that
> difficult to add, does it?


What about something along the lines:

html iframe
        src: (html context actionUrl withParameter: (canvas callbacks
registerActionCallback: [
                self session returnResponse: (WAResponse
                        document: ...
                        mimeType: ...
                        fileName: ....) ]))

This only caches the block that is freed on session timeout and only
accessing the URL generates the document. This is especially useful
for links, when you don't always want to generate the document.

Lukas

>
>         mjl
> _______________________________________________
> Seaside mailing list
> [hidden email]
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
>


--
Lukas Renggli
http://www.lukas-renggli.ch
_______________________________________________
Seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Re: Usage of WAIframeTag

Martin J. Laubach-2
| (html context actionUrl withParameter: (canvas callbacks
|  registerActionCallback: [
|   self session returnResponse: (WAResponse
|   document: ...
|   mimeType: ...
|   fileName: ....) ]))

  Great this works nicely, thank you very much.

  Would it be a problem to cache the result from (html context actionUrl...)
in a Dictionary in my session so that a given document will always give
out the same URL so the browser will cache it?

        mjl
_______________________________________________
Seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside