0

I'm developing a web application using Struts2 (ver. 2.3.24) and I have a massive use of ajax for pagination. I have this form:

<s:form id="pagination-form">
    <s:token id="session_token" />
    <s:hidden id="entityClass" value="%{paginator.getEntityClassString()}" />
    <s:hidden id="paginator-orderColumn" value="%{paginator.orderColumn}" />
    <s:hidden id="paginator-order" value="%{paginator.order}" />
    <s:hidden id="paginator-firstItem" value="%{paginator.firstItem}" />
    <s:hidden id="paginator-resultsCount" value="%{paginator.resultsCount}" />
    <s:hidden id="paginator-perPageItems" value="%{paginator.perPageItems}" />
    <s:hidden id="paginator-currentPage" value="%{paginator.currentPage}" />
</s:form>

And this is the corresponding ajax call:

$.ajax({
        url: route/to/action,
        type: 'POST',
        data: {
            'entityClass': $('#entityClass').val(),
            'struts.token.name': $(form).find('input[name=\'struts.token.name\']').val(),
            'token': $(form).find('input[name=token]').val(),
            'paginator.orderColumn': $('#paginator-orderColumn').val(),
            'paginator.order': $('#paginator-order').val(),
            'paginator.firstItem': $('#paginator-firstItem').val(),
            'paginator.resultsCount': $('#paginator-resultsCount').val(),
            'paginator.perPageItems': $('#paginator-perPageItems').val(),
            'paginator.currentPage': $('#paginator-currentPage').val()
        },
        dataType: 'json',
        success: function (response) {
            // EMPTY THE TABLE
            // ITERATE RESULTS
            // POPULATE THE TABLE
        }, 
        error: function (jqXhr, textStatus, errorThrown) {
            // SHOWS ERROR MESSAGE
        }
    });

When I do the call, the token is invalidated and what i need is to refresh it everytime I have to do a pagination call. I've found this question and this question concerning the topic. There are better ways to refresh the token? Or, on the other side, am I doing something wrong?

Community
  • 1
  • 1
IlGala
  • 3,331
  • 4
  • 35
  • 49
  • Why do you need token at all in pagination? You can refresh your form in success also. – Aleksandr M Jul 14 '15 at 08:34
  • You think i should exclude the token at all? – IlGala Jul 14 '15 at 08:37
  • If you don't know why you are using it... well, then it is hard to say. – Aleksandr M Jul 14 '15 at 08:38
  • Well, mostly because when a user (for example) clicks on the "id" column to be in descending order, this "preference" is saved into the session. I thought that the use of the token would avoid problems when the user performs multiple clicks on different columns – IlGala Jul 14 '15 at 08:44
  • Someone clicks multiple times on different columns. So what? – Aleksandr M Jul 15 '15 at 09:11

0 Answers0