-1

I have a collections of News objects:

List<News> news = new ArrayList<News>();

On my jsp file, I use Struts' iterator to display the first 6 elements of my List.

<s:iterator id="iter" value="news" begin="0" end="5"> 
  <p><s:property value="title" /></p>
</s:iterator>

Assume I have a 'Load more' button on my page which adds 6 more elements when pressed. I want this button to change the 'end' attribute of my iterator to 11. Is it possible doing this with jQuery?

Maybe something like this:

$(document).ready(function() {
   $("a#button").on('click', function(e) {
    var end = $(.iter).attr('end');
    end += 6;
    return true;
    });
});

If not, what's the best alternative?

Thank you

Bravo
  • 1,944
  • 4
  • 29
  • 53

1 Answers1

0

Your jsp code (along with struts) is run run on the server, and the resulting HTML is sent to the client.

Javascript runs in client in general (Except for Node.js like environments) - It doesn't have access to your JSP which resides in the server. AFAIK, You can't simply modify struts attribute using JavaScript, like you're expecting.

jQuery is a javaScript library, so it is not possible doing this with jQuery as well.


You can sent a request to the server with a querystring parameter indicating that it is a load more request, and regenerate the page accordingly (Change struts parameter, query or whatever it takes)

or, You can send an AJAX request to the server on click of the button, get the results back and update the page.

For both the cases, you need to write corresponding server side code. This can't be done using client side scripts alone.

T J
  • 42,762
  • 13
  • 83
  • 138