How to pull the servlet resource and request parameters into HTL script and assign dynamically

Avatar

Avatar

CT1012

Avatar

CT1012

CT1012

22-01-2019

1) Currently i'm providing static URL path as datasource instead of servlet path, i tried the below method from pagination but not working

  1. dataSource: function(done) {
  2.   $.ajax({
  3.   type: 'GET',
  4.   url: '/bin/amica/searchResultsServlet?q=' + 'queryString',
  5.   success: function(response) {
  6.    done(response);
  7.    }
  8.    });
  9. }

2) How to include query parameters in HTL script. For example I need to get the parameter value 'q'' attribute it to queryString dynamically after every request?

<script>

    $('.demo').pagination({

               dataSource: 'http://localhost:8080/bin/amica/searchServlet?q= + 'queryString',

        locator: 'searchResults',

        pageSize: 5,

        prevText: "Previous",

        nextText: "Next",

        callback: function(data, pagination) {

            var html = template(data);

            $('.datacontainer').html(html);

        }

</script>

Accepted Solutions (0)

Answers (2)

Answers (2)

Avatar

Avatar

cquser1

Avatar

cquser1

cquser1

22-01-2019

Hi,

Just sharing few thoughts on above :

1] It is preferred to use servlet resolution by resource type[sling.servlet.resourceTypes] than by path[which you have implemented].

2] For pagination[probably another way without servlet would be to] use the result provided by the querbuilder "searchResult = query.getResult();" in the model where querybuilder is used and get the pagination to work.

3] To get the query parameter in model class, 

    @SlingObject

    private SlingHttpServletRequest request;

searchTerm = request.getParameter("q"); should work.

Avatar

Avatar

smacdonald2008

Total Posts

12.7K

Likes

1.4K

Correct Answer

2.3K

Avatar

smacdonald2008

Total Posts

12.7K

Likes

1.4K

Correct Answer

2.3K
smacdonald2008

22-01-2019

What are you trying to do. As far as i can see - you are performing a GET operation to a Servlet from HTL component. Now, what - do you want to write the data returned from the GET operation to the HTL component?