[Seaside] DocumentHandler

Annick Fron list at afceurope.com
Fri Jun 5 07:31:07 UTC 2020


Thank you Esteban

> Le 4 juin 2020 à 18:26, Esteban Maringolo <emaringolo at gmail.com> a écrit :
> 
> Hi Annick,
> 
> Yes, the #document: registers a callback with that content "ahead of
> time" (it is, before it is clicked), it is meant to be used when you
> already know the contents, and ideally don't instantiate it several
> times.
> 
> That's why for dynamically created docs you just use the other
> approach, an anchor with a callback that does something like:
> 
> html anchor
>    callback: [WACurrentRequestContext value respond: [:response |
> response document: self buildWAMimeDocument ]];
>    with: 'Generate and and download'
> 
> Regards,
> 
> Esteban A. Maringolo
> 
> On Thu, Jun 4, 2020 at 1:00 PM Annick Fron <list at afceurope.com> wrote:
>> 
>> Hi Esteban,
>> 
>>        I have tried your code
>> 
>>>>> html anchor
>>>>> document: documentContents mimeType:  ( Seaside.WAMimeType main:
>>>>> 'application' sub: 'pdf' ) fileName: 'YourFile.pdf';
>>>>> with: 'Download PDF’
>> 
>> but the issue is that it generates the file when the page is created, and not when the user clicks.
>> 
>> So I have derived a new class DelayedDocumentHandler that takes a GRDelayedSend instead of a string or binary, and generates the document only if needed by evaluating the Delayed send.
>> I have added also delayedDocument:mimeType:fileName: on HtmlAnchorTag.
>> 
>> Annick
>> 
>> 
>>> Le 2 juin 2020 à 15:04, Esteban Maringolo <emaringolo at gmail.com> a écrit :
>>> 
>>> I am using both BS3 and BS4 (in a newer application).
>>> In both cases using Torsten's wrapper:
>>> 
>>> BS3: https://github.com/astares/Seaside-Bootstrap
>>> BS4: https://github.com/astares/Seaside-Bootstrap4
>>> 
>>> Regards!
>>> 
>>> Esteban A. Maringolo
>>> 
>>> On Tue, Jun 2, 2020 at 9:47 AM Annick Fron <list at afceurope.com> wrote:
>>>> 
>>>> Hi Esteban,
>>>> 
>>>>       This is the solution that I will use, thank you all for your answers !
>>>> 
>>>>       For your records, I just use the cairo library to draw the PDF.
>>>> 
>>>>       By the way, is anybody using the Bootstrap library with seaside ?
>>>> 
>>>>       Annick
>>>> 
>>>> 
>>>>> Le 2 juin 2020 à 13:47, Esteban Maringolo <emaringolo at gmail.com> a écrit :
>>>>> 
>>>>> If instead of setting a callback on an anchor, you set a document, it
>>>>> will be treated slightly different.
>>>>> 
>>>>> E.g.
>>>>> 
>>>>> You can do something like:
>>>>> 
>>>>> html anchor
>>>>> document: documentContents mimeType:  ( Seaside.WAMimeType main:
>>>>> 'application' sub: 'pdf' ) fileName: 'YourFile.pdf';
>>>>> with: 'Download PDF'
>>>>> 
>>>>> This will be handled differently to a regular action continuation of a
>>>>> callback and will trigger the download immediately, also the document
>>>>> will be returned as a response to never expire.
>>>>> 
>>>>> In some cases you want to use `document:` and in others it could be
>>>>> more flexible to use a regular `respond:` from the
>>>>> WACurrentRequestContext (e.g. if the decision on the file format or
>>>>> other things are deep down in the logic, away from the anchor).
>>>>> 
>>>>> E.g.
>>>>> 
>>>>> WACurrentRequestContext value respond: [:response |
>>>>> response
>>>>>  attachmentWithFileName: self exportedFilename , '.pdf';
>>>>>  doNotCache;
>>>>>  contentType: ( Seaside.WAMimeType main: 'application' sub: 'pdf' );
>>>>>  binary;
>>>>>  nextPutAll: pdfContents;
>>>>>  respond
>>>>> ]
>>>>> 
>>>>> Or directly pass an instance of WAMimeDocument to the response.
>>>>> 
>>>>> WACurrentRequestContext value respond: [:response |
>>>>> response document: aWAMimeDocument
>>>>> ]
>>>>> 
>>>>> Best regards,
>>>>> 
>>>>> Esteban A. Maringolo
>>>>> 
>>>>> On Tue, Jun 2, 2020 at 6:20 AM Annick Fron <list at afceurope.com> wrote:
>>>>>> 
>>>>>> Hi, I would like to serve a custom dynamically generated PDF file, what is the best option ? Use a DocumentHandler ?
>>>>>> If yes how ?
>>>>>> 
>>>>>> Annick
>>>>>> _______________________________________________
>>>>>> seaside mailing list
>>>>>> seaside at lists.squeakfoundation.org
>>>>>> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
>>>>> _______________________________________________
>>>>> seaside mailing list
>>>>> seaside at lists.squeakfoundation.org
>>>>> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
>>>> 
>>>> _______________________________________________
>>>> seaside mailing list
>>>> seaside at lists.squeakfoundation.org
>>>> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
>>> _______________________________________________
>>> seaside mailing list
>>> seaside at lists.squeakfoundation.org
>>> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
>> 
>> _______________________________________________
>> seaside mailing list
>> seaside at lists.squeakfoundation.org
>> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
> _______________________________________________
> seaside mailing list
> seaside at lists.squeakfoundation.org
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside



More information about the seaside mailing list