views:

45

answers:

1

Suppose an 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?

+3  A: 

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.

duffymo
Yes, we thought about that. But we try to save compatibility with js disabled clients. Maybe there is exist another template engine which fit better for this task?
dotsid