feder
feder

Reputation: 2058

Lazy data Loading with JSF (2.2)

Without using REST, how would you load additional data (not a table-like data set), like a scrolling calendar, with JSF 2.2?

The lazy loading should be triggered when the user reaches the bottom of the html document. That is fairly simply to do with jQuery:

        <script>
        $(window).scroll(function() {
            if($(window).scrollTop() == $(document).height() - $(window).height()) {
                   // retrieve server data: from what service? JSF or REST?
            }
        });
        </script>

But how do you retrieve additional days with JSF 2.2 (or Richfaces)? Let's say... 28 days more for the calendar. Reading other threads on this topic, JSF is not recommended. So, am I correct in saying, that a) one should pair JSF to create the initial page and b) use REST for the additional data loading as a solid approach and without abusing JSF for what it is not.

If I imply wrongly, what is the best approach when working on a JavaEE (Wildfly, 8.1) application server with JSF?

Thanks

Upvotes: 1

Views: 356

Answers (1)

feder
feder

Reputation: 2058

I found the following a reasonable approach on how to send a request in order to retrieve JSON data with JSF2+ and then enrich the DOM with this data. I.e. in my case, load more dates on my scrolling calendar.

https://community.jboss.org/wiki/RichFacesCookbookJsFunctionJson

This is with JSF2+ and RichFaces. Doubtless, this can also be achieved with a REST resource and jQuery.getJSON(). That is fine, too.

However, if I was asked to reflect on the employment of sending JSON data using a managed bean or CDI bean, I would agree that it is an abuse. Since it's fine to provide a complex object over a backing bean. And thus it is okay to send JSON data. In particular I find this useful, when one intents to connect that lazy loaded data with other data elments of teh same backing bean. E.g. add new reservations to freshly lazy-loaded dates and push it to the business logic and persistence layer.

Upvotes: 1

Related Questions