2 Replies Latest reply on Sep 20, 2012 3:55 AM by fastridingzebra

    Datatable empty after function call with redirect?

    fastridingzebra

      Hy,

       

      I´m using a datatable on "example.jsf" with commandlinks in each column:

       

      <rich:column>
           <h:commandLink id="bla" action="#{formBean.selectCombination()}">
                <h:graphicImage value="resources/icons/log.png" />
           </h:commandLink>
      </rich:column>
      

       

      When clicking the button in my bean-function selectCombination() I do a redirect:

       

      context.getExternalContext().redirect("combinationSelected.jsf");
      

       

       

      Everything fine so far but when I use my browsers "back" button or manually go back to example.jsf my datatable is empty.

       

      In debugger the getter method for my datatable content is called, and the content is there but it is not rendered.

       

      My bean is session scoped.

       

       

       

      Thanks for any help

        • 1. Re: Datatable empty after function call with redirect?
          healeyb

          Is the browser caching the page? try running with a decent browser such as chrome or firefox and see if the page is being served

          from the cache, using the developer tools network tab or firebug.

           

          The response headers in a .jsf page need to be set so that the page isn't cached which you'd do in a servlet filter:

           

           

          response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.

          response.setHeader("Pragma", "no-cache"); // HTTP 1.0.

          response.setDateHeader("Expires", 0); // Already expired

           

          sharp eyed readers will spot BalusCs original comments! you'd also typically setup response headers to ensure that you do

          cache your static resources such as css and images.

           

          This is one of those things with JSF that aren't all that immediately obvious and can take a lot of time to get right. I probably spent

          3-4 weeks getting a cache filter exactly right.

           

          http://stackoverflow.com/questions/49547/making-sure-a-web-page-is-not-cached-across-all-browsers/2068407#2068407

          http://stackoverflow.com/tags/servlet-filters/info

           

          Regards,

          Brendan.

           

          p.s. the other thing I was going to ask is which jsf version are you using? with JSF 2 the action method can just

           

          return "combinationSelected.jsf?faces-redirect=true"; - this will do a post-redirect-get and the URL will show the

          correct value rather than lagging a step behind.

           

           

           


          Freelance Java Enterprise Developer


          JSF Richfaces Ajax Java 6/7 (scjp) EE 6 HTML CSS JavaScript jQuery MySQL JPA Hibernate Eclipselink

          Spring Oracle SQL JPQL Sybase EJB CDI Glassfish Apache JAX-RS Primefaces UNIX Paypal and more..

          • 2. Re: Datatable empty after function call with redirect?
            fastridingzebra

            Hy Brendan,

             

            thx for your suggestions. I looked into the cache thing but even when I manually emptied the cache before going back to "example.jsf"

            the problem remained.

             

            Here is how I solved it (maybe someone can explain to me why this is working and how ... would be great!)

            Instead of creating a request by using commandlink I used:

             

            <a4j:ajax event="click" listener="#{formBean.selectCombination}" />

             

            So when using ajax instead of a request when I go back now me datatable still has all the content.

            Remember my bean is session scope... so I thought it would not make any difference if I use ajax or request in my special case.

            What do I miss here?

             

            Thx