tags:

views:

1324

answers:

2

Is there a way to get struts 2 (using tiles) to build the whole page before sending it to the browser? I don't want the page to be build "progressively" in the browser one part at a time.

The main problem I'm trying to solve is that internet explorer 7 flashes/blinks the page even if only some of the content changes (firefox does this much more smoothly).

So that if I have a page with:

HEADER

some content

FOOTER

And the "some content" area only changes between page loads, the FOOTER part still flashes the white background before filling it with the background color of the footer. I tought that maybe by getting struts to send the complete page it would load fast enough to eliminate the "blinking". Now the FOOTER comes from the server a little bit later than the parts before it and so it flashes (in internet explorer, firefox displays the page smoothly).

NB: this is an important requirement for the site, and using ajax to load the middle content is out (as are frames or other "hacks"). The site is built using CSS and not a table layout, maybe I will have to use a table layout to get it to work...

About using tiles flush parameter: I tried that and it doesn't work as I need. I would need a flush-parameter for the whole page. I have tried the normal jsp page directive "autoFlush=false" but it didn't work. I set this directive on my main template page (and not in the tiles).

Here is an example from the main template, which uses header, body and footer templates. With the Thread.sleep() I added the problem is easy to spot. The footer renders 2 secs later than the rest of the page.

  <body>
  <div id="container">
  <t:insertAttribute name="header" flush="false" />

  <div id="content"><t:insertAttribute name="body" flush="false"/></div>

  <div class="clear"></div>
  <% Thread.sleep(2000); %>
  <t:insertAttribute name="footer" flush="false" />
  </div>
  </body>

UPDATE

Thanks for the comments. The requirement is actually almost reasonable as this isn't a normal web page, think embedded.

But apparently there is no way of configuring IE to start rendering after some delay (like firefox has a configurable delay of some 100ms)?

I tried to intercept the TilesResult but the method doExecute is run before the whole content is apparently evaluated, so the method has already exited before the jsp is evaluated (my Thread.sleep() test). I was wondering how I could render the whole response to a string and then output that all at once to the browser.

I know that this isn't foolproof and network delays etc may factor in this, but if I could get the response to output all at once and maybe use a table based layout (IE possibly renders the table only after the table closes) this could work reasonably.

Or then try to get this switched to firefox or maybe forget all about this little glitch...

UPDATE 2

This started to bother me so I did some investigation. If I had a plain jsp page (no tiles) the buffering works (with the buffer attribute), so that if I had my Thread.sleep() there the whole page rendered after two seconds if the page size was below the buffer size. But if I used tiles in the page (as in the example above) I couldn't get the page to render at the same time (I even included the page directive in all my tiles-templates/"components", no help). So tiles probably flushes the response somewhere?

Furthermore, the "problematic tiles" was my body-part, which contained a struts:form tag. I replaced it with a normal form-tag and it worked as I wanted...

UPDATE 3

Ok, nobody seems to know the inner workings of tiles or struts tags... No big problem as this is a very specific case and requirement. I worked around it by using apache as a proxt in front of the application, and using apache's proxy configuration options to specify a large buffer. I'll mark this as answered.

A: 

Can you use the "flush" attribute on the tiles components?

<tiles:insertAttribute name="body" flush="false"/>

In addition if the output buffer gets too big, it will flush anyway. Try increasing the buffer size?

<%@ page language="java" buffer="500kb" autoFlush="false" %>
JeeBee
Yes I tried that also, no difference :(
Frontline
Alas. Can you silently replace IE on your bosses machine with Firefox themed like IE?
JeeBee
A: 

You can send page data all at once at the server end if you like (and many frameworks do that anyway for convenience) but the reality of networking is that it won't all arrive at once and the browser will render it as packets arrive. And this is a good thing for responsiveness, even if you* aesthetically would like the page to display all at once.

You can reduce the lag as much as possible by simplifying markup and using deflate compression to keep the payload size down, and that's a worthwhile thing to do in general. Plus you can make sure you're not hitting a Flash Of Unstyled Content. But you can't control when the browser chooses to render, short of doing it all in JavaScript with all the downsides that entails (and even then, the browser might redraw slowly).

(* - or your client/boss, if that's who has come up with this "important requirement" that your site somehow work differently to every other page on the web.)

bobince