0
votes

It is not long ago that I asked this question, which was about updating a property bundle after a csjs-induced full refresh. I solved it with a URL-parameter that lead to a context.redirectToPage.

Now I have an xPage with a jquery-based jqGrid, which receives a string with JSON-data from the viewScope and displays that data in a table. When I edit a record in the grid and hit 'submit' the grid posts a parameter called 'oper' with values like 'edit', 'add', etc., for which I check in the beforePageLoad event of the page and then execute the save method of my managed bean. After this I update the viewScope variable with the new JSON-string and conduct a full refresh in the above mentioned manner which had worked before.

<xp:this.beforePageLoad><![CDATA[#{javascript:
    if (bccUser.isAdmin() && param.containsKey('oper') && param.get('oper').toString().length>0) {
        bccGridDataHandler.saveGridDoc('RequestDummy','PersonRequestsDummy',param);
    }
    viewScope.put('jsonString',bccView.getViewColumnValue('PersonRequestsDummyJson',1));    
    print('jsonString in viewScope: '+viewScope.get('jsonString'));
    if (bccUser.isAdmin() && param.containsKey('oper') && param.get('oper').toString().length>0) {
        var url = context.getUrl().toSiteRelativeString(context);
        if (url.indexOf('?')!=-1) {
            url += "&doRefresh=true";
        } else {
            url += "?doRefresh=true";
        }
        print("redirecting to: "+url);
        context.redirectToPage(url);
}}]]>

In the server console I can see the correct, updated JSON-string from the first print statement, so the save-method was successful and I have up-to-date data in my viewScope. The grid, however, does not show the updated data, neither does my test-div

<xp:text value="#{javascript:viewScope.get('jsonString')}" />

I also tried a partial refresh on the grid and div after updating the viewScope, but the same happened. After a manual refresh of the page everything is fine again. So, what's happening here? I just want to pass a simple string to a control. Am I mistaken again about the xPages-Lifecycle and the order of events?

Thanks in advance. Regards, Sarah

3
Have you tried to synchronize your viewScope calls?Sven Hasselbach
Are you redirecting to the same page? If so, try using context.reloadPage() instead.Mikael Andersson Wigander

3 Answers

0
votes

I think you are losing the viewScope value in the redirectToPage. Try with requestScope or sessionScope.

0
votes

Thanks for all the suggestions, I tried them all out but unfortunately with no luck. The most interesting thing about this was, that when I put a clientside alert statement into the onClientLoad event it would just fire once, when I enter the page, but not after any of the context.redirect or .reload commands. After all I solved the problem the following way:

I removed the redirect command from the beforePageLoad event and added the following parameter to the submit function of the jqGrid (see documentation here):

afterSubmit: function(response, postdata) {window.location.href=window.location.href;return [true,'',''];}

This works for me (onClientLoad is also triggered again after this), but still I wonder why a page refresh induced from the serverside doesn't do the same thing as a clientside refresh, or isn't able to imitate a clienside refresh.

0
votes

I am not sure if the beforePageLoad event is the right one, have you considered generating the JSON in beforeRenderResponse?