Partial Update...why I need 2 refresh for see the change? - xpages

I have a simple question:
I have a ViewPanel with my view and I have 3 button (action button) named
REMOVE ENTRY
MARK UNREAD
MARK READ
every 3 action execute a partial Update of my View after SSJS routine
REMOVE ENTRY: call a simple SSJS doc.remove(true);, but my ViewPanel show the entry after the refresh of this action (But if you execute another partial refresh the entry isn't correctly show into ViewPanel)
MARK READ: call a simple SSJS document1.getDocument().markRead(); and work correctly after the partial refresh of button event handler!
MARK UNREAD: call a simple SSJS document1.getDocument().markUnread(); but I have same problem of the action REMOVE ENTRY (after the event handler automatically partial refresh of BUTTON i don't see any change into ViewPanel...I need to execute another partial update after...and I see unreaded the entry)
Have someone any suggest?

I had experienced the similar issue. I don't say the solution I found is good one.. but atleast it is working for me.
After finish of every action which you are performing on the viewpanel, inside the event handler try putting this code :
<xp:this.onComplete><![CDATA[XSP.partialRefreshGet("#{id:viewPanel1}", {
onComplete: function() {
//
}
});]]></xp:this.onComplete>
This will refresh the view Panel, once your action gets finished.

Related

Execute XPages SSJS code if complete refresh, not partial refresh?

I have an XPage with some SSJS code that I'd like to execute in the case of a complete refresh. (It's also okay if it executes on initial page load, I guess.) If a partial refresh of a component on the page has occurred on the page, then I don't want the code to execute. Is it possible to distinguish these cases? It feels like I need to set a state variable in viewScope to be able to do this.
For context, the partial refresh is a user clicking on the links of a pager to move through chunks of view elements. The intitial/complete refresh case is performing a FTSearch on the view. That should only be done when the user clicks on other links on the page that are used to filter the view.
The XPages lifecycle and event handlers are still a mystery in some ways.... Thanks in advance!
Add your SSJS to the beforePageLoad or afterPageLoad, depending on what's available). Those events are only triggered during the initial page load, which you can see by adding print("Running beforeRenderResponse"); to the event and looking at the server console.
In events where you want to run the code again, use context.reloadPage(); at the end.
The same XPages lifecycle is processed for refreshMode="partial" and refreshMode="complete".

XSP.partialRefresh does not fire after XSP.confirm

Short overview of my issue: I have a large form with several fields, one of them is a xe:djFilteringSelect and one a xp:combobox. The xp:combobox is computet depending on the value selected in the filtering select. Now my customers want that if they change the value of the filtering select of a already saved docoument they should be prompted with a warning. So i want to add a confirm message to the onChange event of the djfilteringselect to cancel it's SSJS code wich changes the combobox.
Prompting the user with a confirm ("change value?...") box is no big deal but reseting the value back (on ClientSide) if the users selects "no" gives me a lot of trouble.
What i have already tryed:
If i use a simple confirm action all further onChange actions get canceled but the djFilteringSelect field keeps it's user selected value. So if i fire a partial refresh on the filtering select the original value form the document is displayed but i don't know where to add it because there is no onCancel or did i miss something here?
I also tried it from the CSJS with window.confirm and XSP.confirm and reset the value manual with a XSP.partialrefreshGet() if the user selects 'no' but in this case the partial refresh does not work:
if(!XSP.confirm("execute?")){
XSP.partialRefreshGet("#{id:repeat1}",{
onStart: function () {console.log("start");},
onComplete: function () {console.log("finish");},
onError: function () {console.log("error");}
});
return false;
}
If i move the partial refresh to a function and call it from e.g. firebug it works fine but if i call it inside the if(confirm){} it does nothing at all. The return false does work the SSJS does not get executed. The value in the document is not changed (as intended), but the djFilteringSelect keeps the selected value on the ClientSide.
I also tried Mark Leusink´s dojo-style Confirm but same Problem with the partial refresh here.
If i set the value back manual instead of using a partial refresh with dijit.byId(item).setValue it will resoult in another onChange Event... loop. Update: If i use dijit.byId(item).set("value",newVal,false) the onChange does not fire direct it changes the value as intended but then the onChange fires when the filtering select looses ist ??focus!?!? ...
So my questions:
Is there a ways to execute any Code after the confirm action if the user selects "no".
Why is the partial refresh in my CSJS not working (i dont see any traffic in firebug and i dont get any errors not even the onError of the refresh gets fired).
Does anyone know a different approach to my problem?
update:
My current 'solution' is to use window.location.reload() instead of the XSP.partialRefresh to reload the site. But this solution does not really satisfy me, because in IE the whole page is flickering.. in firfox i can live with it.

#{javascript:viewScope.something} won't update after context.redirectToPage(...)

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
I think you are losing the viewScope value in the redirectToPage. Try with requestScope or sessionScope.
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.
I am not sure if the beforePageLoad event is the right one, have you considered generating the JSON in beforeRenderResponse?

XPages XSP.partialRefreshGet strange effect on view container control

My theme is OneUI2 ...
On my XPage I have a VDS (view data source) and when links are clicked the associated document is loaded into a DDS below. I have a save button with 'No Update' set and the button event handler doing a partial refresh on the DDS and onComplete it does a partial refresh in the VDS. All works great, but something is happening to the view.
View Source shows the view inside a TABLE tag and after the partialRefreshGet on the VDS the table tag gets duplicated inside that 1st TABLE tag, so now I have a TABLE tag inside another TABLE tag (I'm ignoring the TR and TR tags here) and so on after each save of the VDS.
If I change the button to do a partial refresh of my VDS and the event handler to do a partial refresh of the DDS it works! But any CSJS doing a partial refresh of a VDS goes wrong.
Why is this happening and how can I stop this?
Has anyone done a partialRefreshGet on a VDS and got it to work without table tag getting added after each save?
There are 2 things you can try to continue using CSJS to perform partial refreshes:
Make sure the Syntax of your XSP.partialRefreshGet is correct. Note the second argument of {} if you are not performing indented partial refreshes.
Syntax:
XSP.partialRefreshGet(yourId, {});
Try XSP.partialRefreshPost as a possible alternative. I sometimes have to jump between the 2 to get the results I'm looking for.
XSP.partialRefreshPost(yourId, {});

client message after SSJS routine how?

I have a Button that in SSJS send and Email...
Now I would if is possibile show the status of sending of email in real-time to the user:
sending process....
sending Successful or sending error
How Can i call a JS client codice from SSJS routine?
Have you any suggest?
If you are using ExtLib then you can also use the #WarningMessage('messageText') method.
You will need to add a section to the XPage to display the messages. It can be as simple as
<xp:messages id="messages1"></xp:messages>
Once added each call to #WarningMessage will add a line to the messages pane.
8.5.3 introduced a very nice approach:
view.postScript
you may insert any CSJS code you like from the SSJS code.
This is quite straightforward.
1. Add a Hidden Input control on your page, noting the id.
2. In your SSJS use getComponent("inputHidden1").setValue("This is the message")
3. Ensure the Hidden Input control is in the area being refreshed (otherwise the value doesn't get passed back to the browser, so can't be accessed in CSJS)
4. Go to the Source pane and place the cursor on or in the eventHandler that is triggering your SSJS. You need to do this to get to the onComplete event
5. In All Properties panel go to onComplete, add your CSJS there. e.g. alert(dojo.byId("#{id:inputHidden1}").value)
This will run your SSJS and on completion alert the user with whatever code is in the field.
For a demo and demo code, check out my blog post: http://www.intec.co.uk/xpages-calling-client-side-javascript-from-server-side-javascript/
Another way to do it besides Pauls answer is to use a dialog from the extlib, and you can call it from ssjs, put a field in a dialog and set it to a scope value and show the dialog.

Resources