开发者

Two pass JSP page rendering

Suppose a开发者_Go百科n example. I have following interface:

public interface DataSource<T> {

  Future<T> fetch();
}

This datasource can do asynchronous data fetching. And we have following tag for using datasource in JSP:

<html>
  <d:fetch from="${orderDS}" var="orders">
    <c:foreach in="${orders}" var="order">
      <div class="order">
        <c:out value="${order.title}" />
      </div>
    </c:foreach>
  </d:fetch>
</html>

So, what I want? I want JSP rendering engine to call my custom tag (FetchTag in this example) twice. On first call FetchTag will do DataSource.fetch() call and save Future locally as a object field. On second call FetchTag do Future.get() call and will be blocked until data becomes available.

Is there any way to do such a thing?


I think a better design would not try to alter JSP rendering. Put all that database code on the server side, where it belongs, and use an AJAX call to get that data from a server-side component.

In general, I've found that embedding stuff in custom tag libraries is a bad idea. JSTL and/or Spring tag libraries are all that I need. If I feel like my UI needs to do more, I'm thinking about it incorrectly.

For JS disabled clients, I'd just make them do the round trip for the data and not try to do it in the background. Give them a choice: wait or turn on JS.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜