You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Chuck Kring <cj...@pacbell.net> on 2010/07/21 00:15:33 UTC

directly return an image from Tapestry

Hi everybody,

I need to create a watchdog on a page that reloads the entire page when 
I detect the server has restarted.  

So far, my approach is to retrieve and image from the Tapestry web app 
by setting an image src field, then reloading or not based upon onload 
vs.onerror event handlers.   This tests the webapp and server and I can 
reload the page if I receive an onload after an onerror event.

In other words....

var img = new Image();
img.onerror = imageFailed;
img.onload = imageLoaded;
failed = false;
setTimeout( doPoll, 10000);

doPoll(){
    img.src = location.locationhost + "/t/testpage/" + Date.UTC();   // 
to prevent image caching
}

imageFailed()
{
    failed = true;
    setTimeout( doPoll, 10000);
}
imageLoaded()
{
    if( failed == true ){
        location.reload(true);
    } else {
       setTimeOut(doPoll, 10000);
    }
}

I *think* I need to create a Tapestry page that returns an Asset or 
StreamResponse.   I don't want to handle this as an event on the watched 
page because I'm not sure how Tapestry will handle the event if the 
server has restarted.

So, it is possible for a Tapestry page to return a streamresponse?  Or 
is there a better way to do this?    I hesitate to use Ajax requests 
because I'm not sure that I'll be able to differentiate between the 
server not up yet and Tapestry not knowing what to do with old Ajax 
requests from another session.  Images seem easy from the Javascript 
side but I'm not sure how to handle this in tapestry.

Regards,

Chuck Kring


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: directly return an image from Tapestry

Posted by Chuck Kring <cj...@pacbell.net>.
That was simple and effective.   Thanks!

Chuck

Thiago H. de Paula Figueiredo wrote:
> On Tue, 20 Jul 2010 19:15:33 -0300, Chuck Kring <cj...@pacbell.net> 
> wrote:
>
>> Hi everybody,
>
> Hi!
>
>> I don't want to handle this as an event on the watched page because 
>> I'm not sure how Tapestry will handle the event if the server has 
>> restarted.
>
> It will, no doubt about that.
>
>> So, it is possible for a Tapestry page to return a streamresponse?
>
> Just return it in the page's onActivate() method.
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: directly return an image from Tapestry

Posted by Chuck Kring <cj...@pacbell.net>.
Thanks for the warning.  I'm using this to serve a 1-pixel gif file 
every 20 seconds so I don't think this will cause performance issues.  
Note taken though.....

Chuck

Peter Stavrinides wrote:
>> Just return it in the page's onActivate() method.
>>     
> Just be careful of this approach, its fine for an image or two, but anything more may generate a lot of requests and cause performance problems in larger pages.
>
>
> ----- Original Message -----
> From: "Thiago H. de Paula Figueiredo" <th...@gmail.com>
> To: "Tapestry users" <us...@tapestry.apache.org>
> Sent: Wednesday, 21 July, 2010 01:22:31 GMT +02:00 Athens, Beirut, Bucharest, Istanbul
> Subject: Re: directly return an image from Tapestry
>
> On Tue, 20 Jul 2010 19:15:33 -0300, Chuck Kring <cj...@pacbell.net>  
> wrote:
>
>   
>> Hi everybody,
>>     
>
> Hi!
>
>   
>> I don't want to handle this as an event on the watched page because I'm  
>> not sure how Tapestry will handle the event if the server has restarted.
>>     
>
> It will, no doubt about that.
>
>   
>> So, it is possible for a Tapestry page to return a streamresponse?
>>     
>
> Just return it in the page's onActivate() method.
>
>   

Re: directly return an image from Tapestry

Posted by Peter Stavrinides <P....@albourne.com>.
> Just return it in the page's onActivate() method.
Just be careful of this approach, its fine for an image or two, but anything more may generate a lot of requests and cause performance problems in larger pages.


----- Original Message -----
From: "Thiago H. de Paula Figueiredo" <th...@gmail.com>
To: "Tapestry users" <us...@tapestry.apache.org>
Sent: Wednesday, 21 July, 2010 01:22:31 GMT +02:00 Athens, Beirut, Bucharest, Istanbul
Subject: Re: directly return an image from Tapestry

On Tue, 20 Jul 2010 19:15:33 -0300, Chuck Kring <cj...@pacbell.net>  
wrote:

> Hi everybody,

Hi!

> I don't want to handle this as an event on the watched page because I'm  
> not sure how Tapestry will handle the event if the server has restarted.

It will, no doubt about that.

> So, it is possible for a Tapestry page to return a streamresponse?

Just return it in the page's onActivate() method.

-- 
Thiago H. de Paula Figueiredo
Consultor, desenvolvedor e instrutor em Java, Tapestry e Hibernate
Coordenador e professor da Especialização em Engenharia de Software com  
Ênfase em Java da Faculdade Pitágoras
http://www.arsmachina.com.br

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: directly return an image from Tapestry

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Tue, 20 Jul 2010 19:15:33 -0300, Chuck Kring <cj...@pacbell.net>  
wrote:

> Hi everybody,

Hi!

> I don't want to handle this as an event on the watched page because I'm  
> not sure how Tapestry will handle the event if the server has restarted.

It will, no doubt about that.

> So, it is possible for a Tapestry page to return a streamresponse?

Just return it in the page's onActivate() method.

-- 
Thiago H. de Paula Figueiredo
Consultor, desenvolvedor e instrutor em Java, Tapestry e Hibernate
Coordenador e professor da Especialização em Engenharia de Software com  
Ênfase em Java da Faculdade Pitágoras
http://www.arsmachina.com.br

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org