0

After reading so many examples in the web, I can not find the right answer of the right method to refresh a jsf page programmaticaly. With using a meta http-equiv="refresh" content="20", sometimes, when the network is very busy, I receive "Web page not available" and the user loses his work, but the app is still working and when the user press F5 can continue to work, but that is not a solution. So, are there another ways to refresh a JSF page? Please, note that I have very small server resources (I use raspberry PI) and don't want to use for example Ajax to do this work. Thanks.

seenukarthi
  • 8,241
  • 10
  • 47
  • 68
  • At which event do you want to refresh the page? – Smutje Sep 23 '14 at 10:53
  • Which JEE application server are you running in the raspberry PI? – Yamada Sep 23 '14 at 11:45
  • @Smutje - Well, actually i have a Thread, who check for new items in my store (datatable with status). When the thread finds a new item in the datatable, the thread must notify the client for the new changes. With the old meta tag, i am refreshing the site and my backin bean checks for that. Now i must check with thread and notify my client (users), who waits for that. – user3157099 Sep 23 '14 at 12:09
  • @Yamada - well, i use the integrated Apache Tomcat Web Server, which comes with the standart OS for the raspberry PI - named "raspbian". All of the tools are standart - Java 1.6, Apache Tomcat, Bind9 DNS. – user3157099 Sep 23 '14 at 12:11
  • I'm pretty sure you won't be able to run JSF application on plain Apache Tomcat. Can't you update to TomEE? – Yamada Sep 23 '14 at 12:17
  • @Yamada - i don't know what has to do that with my question, but i will answer you - in the Apache Tomcat library, i just only put 2 jars (jsf, jslt) as a librarys and i can use the specifications. Nothing else. – user3157099 Sep 23 '14 at 12:22
  • @Yamada - well i forgot - some other librarys are needed - but the installation of the Apache Tomcat is plain. – user3157099 Sep 23 '14 at 12:24
  • The point is that if you don't have a compliant web container, the behavior of a JSF application is unpredictable... – Yamada Sep 23 '14 at 12:26
  • @Yamada - sorry, now i undestand your question, sorry - yes, i can try to update to TOMEE, but after that - what must i do to solve my problem? Thanks. – user3157099 Sep 23 '14 at 12:27
  • @Yamada - why can't one run a JSF application on tomcat? – kolossus Sep 24 '14 at 12:41
  • @user3157099 - if you have limited resources, you don't have the luxury of refreshing the entire page. Your refresh should be targeted at specific sections of page – kolossus Sep 24 '14 at 12:43

2 Answers2

0

Because you have small server resources, an ajax approach would be better since it might not refresh your entire page. Please note that you must design it properly.

If this is acceptable, you might use the poll component from PrimeFaces.

<p:poll interval="20" listener="#{yourManagedBean.keepAlive}"/>

Here is a link for a ajax processing question.

Community
  • 1
  • 1
Yamada
  • 723
  • 6
  • 23
  • can you please give an example of the method of the Bean - keepAlive() - i mean, what will be done in this 20 sekonds with calling the "#{yourManagedBean.keepAlive} . Thanks – user3157099 Sep 23 '14 at 15:57
  • it can be a blank method... but if you want to log how long the user is taking on the same screen you can use it for this purpose. – Yamada Sep 23 '14 at 17:50
0

You can also set your homepage as errorPage. If the site is not available your will be redirected to it. Configure this in your web.xml:

<error-page>
    <exception-type>java.lang.Exception</exception-type>
    <location>yourHomepage.xhtml</location>
</error-page>
  • Thanks Mahttias, so clever solution - AND IT WORKS, that's mean that we make an endless loop to check the site and only of the browser site. The Solution with ajax is good, but when we don't have ajax - i think your idea is the best. Thanks. – user3157099 Sep 25 '14 at 08:56
  • It is not the very best solution of the problem, but it will help for me. The problem is that not all of sites, who makes "errors" must go at the end to my error page. Is there a way to make only for that site the error page - not for all? Thanks. – user3157099 Sep 25 '14 at 08:59
  • You can define different error pages for different exceptions. I think with Primefaces 5 is it also possible to define the location of the errorPage dynamically with Expression Language: [link](https://code.google.com/p/primefaces/issues/detail?id=6072&thanks=6072&ts=1377986205) – Mahttias Schrebiér Sep 25 '14 at 09:47