Expand my Community achievements bar.

SOLVED

Efficent way to recursively call back a page from itself to search data held in JSP as an ArrayList<Object>

Avatar

Level 6

If I have a situation where I have an ArrayList generated from an OSGI bundle. The OSGI bundle builds itself upon an API call and then creates an ArrayList of data objects.

This is passed on back to the JSP.

I have a situation where I want to do two types of searches.

1) Limit the result by a filter. When the filter selector (product by type is selected) then only that product type needs be displayed.

- At present I call back the page recursively and pass on the product category as a sling selector, and rebuild the page by re calling the OSGI bundle to return a limited set.

- I could also do this using jQuery. I am not sure which is better, using a sling selectors vs JQuery.

Ideally I would call back the page without having to regenerate the ArrayList. I would then search through the existing ArrayList.

 

Please could any one help me with this. Basically,

(1) Would I be better off to use Sling or JQuery to cal back the page?

(2) Is it possible to use Sling to call the page recursively and access the existing ArrayList and regenerate the display from searching within the ArrayList?

Regards

Clive Stewart

1 Accepted Solution

Avatar

Correct answer by
Employee

Hi Clive,

I'm not 100% sure I understand your requirements here, but I think you should be able to do this without calling back to the server at all. In your rendered HTML, you should output content like this:

<div class="product-data" data-product-type="car">some details about this car</div> <div class="product-data" data-product-type="boat">some details about this boat</div>

Then, when someone clicks on one of your filters, run a bit of JavaScript that shows/hides the corresponding divs:

function filter(type) { $(".product-data[data-product-type != '" + type + "']").hide(); $(".product-data[data-product-type = '" + type + "']").show(); }

HTH,

Justin

View solution in original post

1 Reply

Avatar

Correct answer by
Employee

Hi Clive,

I'm not 100% sure I understand your requirements here, but I think you should be able to do this without calling back to the server at all. In your rendered HTML, you should output content like this:

<div class="product-data" data-product-type="car">some details about this car</div> <div class="product-data" data-product-type="boat">some details about this boat</div>

Then, when someone clicks on one of your filters, run a bit of JavaScript that shows/hides the corresponding divs:

function filter(type) { $(".product-data[data-product-type != '" + type + "']").hide(); $(".product-data[data-product-type = '" + type + "']").show(); }

HTH,

Justin