Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Primefaces dataTable with Ajax

 
Mat Anthony
Ranch Hand
Posts: 261
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm currently developing a JSF website that uses a prime face
table to display a list of products that have been submitted to
my website. Each product has a postcode related to a supplier.
I would like to give a user the option to sort on shortest distance
to the nearest product. I'm currently calling 3rd party software (via web service Restful call)
to obtain the distance between postcodes(i.e. user and supplier). I would like to be able to display
all the products in the table and then make ajax calls to bring back the distance between the
User and seller postcode and then display the distance beside each product in the table.

Not sure if this is the correct approach or how to do it with the sort.
Also if the third party connection is down, I don’t want my web site to be waiting for
the response.

Mat
 
Tim Holloway
Bartender
Posts: 18419
60
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, I think I got that. You want a table that's primarily coming from your database, but you want to augment it with a distance value coming from a third party, correct?

That's easy enough to do. Note that the DataModel for a dataTable is a GUI model, not a persistence model. Often, it's convenient to use the persistence model data directly as a GUI model (since both types of models are JavaBean-based, that's perfectly OK). But sometimes you need variations on that theme. What you could do in that case is define a class that decorates or fronts for the persistence model objects, adds in the distance factor, and build a row in the augmented (GUI) model for each row returned from the persistence model.

You can do variations on this theme, such as caching the distance so that you don't have to go all the way back to the third-party server every time, but that's the basic concept.

If the third-party site is down, you should probably code for the "Circuit Breaker" design pattern and set the distance to a default value as you construct the UI model rows.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!