In an application I want to monitor if changes has occurred in input fields. Therefor I have added the following code to my XPage:
<xp:scriptBlock id="scriptDirtyListener">
<xp:this.value><![CDATA[XSP.attachDirtyUnloadListener("attention");
XSP.addOnLoad(function() {
XSP.attachDirtyListener("#{id:inpFirstName}");
}); ]]></xp:this.value>
</xp:scriptBlock>
but now when open the form, enter a value in my firstname field press refresh or navigate away no warning appears.
What am I doing incorrectly? Or does this only work with domino document data-binding?
Related
I have an Xpage with access set to public for clients to fill in a form. When I send the client the link to the page and they open it for the first time. Everything runs smoothly. However, if they close the browser and click on the link again they receive this error:
{Unexpected runtime error
The runtime has encountered an unexpected error.
Error source
Page Name:/xpClientForm.xsp
Exception
Could not open the document
Invalid universal id}
I am using a switch facet to cycle between forms depending on the client type.
The domino document id is being stored in a sessionScope beforepageload and the document dynamically computes it based on that sessionScope variable.
Here is the code:
SessionScope assignment on beforepageload
var cData = getClientData(id);
sessionScope.docId = cData.docID;
Document datasource
<xp:panel style="height:100px" id="pnlDocData">
<xp:this.data>
<xp:dominoDocument var="document1"
formName="frmA" action="editDocument"
documentId="#{javascript:sessionScope.docID;}" scope="request">
</xp:this.data>
</xp:panel>
However when i execute this custom control on a page that does not have public access. It runs fine with no issues irrespective of how many times i open the link.
Any help will be greatly appreciated.
You need to set ignoreRequestParams="true" on the dominoDocument datasource. Otherwise it's using the document ID in the URL or trying to create a new document, which the user probably doesn't have access to do.
Computing the document ID is the less common scenario, which is using the URL for document location is the default.
I have a save button on my xpage. I have field edits inside of the button. I did that because when I put the edit in the field validation, it runs when I open a new xpage. Either way though, I have an Error Message control on the form. When I click the save button, it flashes yellow then disappears. Why is this occurring? It's simple code:
if(getComponent("ExpAmt").getValue() == null) {
#WarningMessage("You must enter an Amount for this expense");
return false;
}
Partial refresh message box displays saying:
An error occurred while updating some of the page.
Unable to load http://localhost/DB.nsf/xpForm.xsp?$$ajaxid=view%3A_id1%3A_id3%3A_id4%3ApanelAll status: 0
There is a partial refresh in your ccApplicationLayout that runs onClientLoad. It was immediately refreshing the panel after the page was loaded which caused the flashing effect. Removing this solved the issue.
I have an XPages app that is supposed to save the main doc (and do a couple of other things) when the user clicks a button on the dialog box. The dialog box is presented by a CSJS function which runs according to a setInterval command. The dialog box and all the programming that present it are on a Custom Control. I have no problem displaying the dialog box, but have been unable to come up with a way to save the underlying document. I have other dialog boxes on their respective XPages, and saving the doc with a click (and some SSJS) works fine, but the same process doesn't seem to work if the dialog box is on a CC. I have searched all over the web, including StackOverflow, and haven't been able to find just what I need. Any ideas as to what I am missing?
Here's the code from one of my more recent attempts:
<xp:button value="Continue" id="button1">
<xp:eventHandler event="onclick" submit="false" id="eventHandler1">
<xp:this.script>
<![CDATA[
if (intvlID2) {
clearInterval(intvlID2);
}
var b18 = dojo.query('[id$="button18"]')[0];
if (b18) {
b18.click();
} else {
location.reload(true);
}
XSP.closeDialog('#{id:WarningDialog}');
]]>
</xp:this.script>
</xp:eventHandler>
</xp:button>
As you can see, it clears the interval first, then looks for a button on the underlying form. I've been able to verify that it does, in fact, find the button, but nothing happens with the click() command. The button it finds includes this save command that doesn't appear to execute:
document1.getDocument(true).save();
The button works perfectly when clicked by mouse or tapped by finger, but not when 'clicked' programmatically by another button on a CC.
The currentDocument global variable can be used to access the nearest dominoDocument datasource. Alternatively, the Extension Library dialog box has an additional parameter when closing the dialog box, the id of the refresh area. Maybe you can use that to trigger a save, something like setting a requestScope variable on close, and in the refresh area having code that does a save if the requestScope variable is set and, after save, clearing the requestScope variable?
Why does context.redirectToPage behave differently when executed in a view root-event instead of an event handler?
This question came up when I tried to set the language of an xpages application to the language saved in the user profile, once the user is logged in. I use a properties-file with translated strings in a resource bundle, and retrieve the strings like this:
<xp:text value="${langString['WELCOME_TEXT']}" />
When the language is changed and so a different properties-file is loaded, the page needs to be refreshed in order to update those strings. This worked fine when I added a full-refresh event handler to the login button, that executed a server side context.redirectToPage(). No luck with client side refreshes like location.reload or window.location.href=window.location.href (the login-function itself is a client side function though).
But of course the user expects that he is also logged in when he presses the enter key instead of the button after he has entered his credentials. So I added an onkeypress-event to the username and password input fields, and checked for the enter key (if (thisEvent.keyCode==13) dosomething...) before executing the login function.
But now the event handler is called every time a key is pressed and of course I do not want the context.redirectToPage to be executed all the time.
Thus I removed the server side event handlers and changed the login function so that it terminated with a partial refresh of the div containing the whole page:
var p = {"execLogin":"true"}; XSP.partialRefreshPost( '#{id:wholePage}', {params: p} );
The parameter sent via the partial refresh now triggers an event in which our context.redirectToPage is executed:
<xp:this.beforeRenderResponse><![CDATA[#{javascript:if (param.containsKey('execLogin') && param.get('execLogin').toString().equals('true')) {
print("test");
context.redirectToPage(context.getUrl().toSiteRelativeString(context),true);
}}]]></xp:this.beforeRenderResponse>
The page is refreshed and "test" is printed out, but I still see the old language strings. I have to refresh the page manually again to make the new user language take effect.
Any idea how to execute a genuine full refresh this way, or maybe another way to update the strings retrieved from the property bundle?
Thanks in advance. Regards,
Sarah
EDIT
I now have:
<xp:inputText id="cc_login_panel_login_username" styleClass="span2">
<xp:eventHandler event="onkeypress" submit="true" refreshMode="complete">
<xp:this.script><![CDATA[if (thisEvent.keyCode!=13) {
return false;
} else {
doLogin();
return true;
}]]></xp:this.script>
<xp:this.action><![CDATA[#{javascript:context.redirectToPage(context.getUrl().toSiteRelativeString(context));}]]></xp:this.action>
</xp:eventHandler>
Because context.reloadPage() didn't even log me in somehow (strange) I got back to using redirectToPage. The server side event is fired once and at the right time *thumbs up*, but the language properties-bevaviour is still the same.
$ is only set on page load, whereas # is set each time during the partial refresh.
I don't think a partial refresh will work at all though. This will refresh the computed field. However, it will need a full refresh to refresh the part of the XPage that includes the properties file. In other words, you would be refreshing the computed field, but using the same properties file.
I wonder if context.redirectToPage or context.reloadPage is somehow going to the same page but with the cached properties files.
If you're always wanting to come back to the same page, a full refresh instead of partial refresh may be the best option.
I think this has something to do with using the $ parameter. this tells the runtime to retrieve the language file the first time the current page is created in the back-end. When a user does a refresh it is actualy retrieving a saved version of the page you are viewing.
I see you're calling "context.redirectToPage(context.getURL().toSiteRelativeString(context)))" within an xp:this.action tag for the xp:eventHandler.
Try using xp:this.onComplete in place of xp:this.action.
According to the Designer tooltip for the action, the expected return is a string to be passed to the navigation handler. So instead giving the onComplete will execute the redirect command when it's done with the eventHandler group of events.
Thanks for all the helpful answers, in fact all of them did work, the problem turned out to be my misunderstanding of when the properties-file is loaded. It is loaded in an early phase, long before my new language is set to the sessionScope (that sessionScope variable is then used as a part of the name of the properties-file to be loaded, via the VariableResolver).
Now I use a double full refresh to load the new file. When the login function terminates successfully, it executes:
window.location.href = window.location.href + "?doRefresh=true";
And to the view root element I added the following event:
<xp:this.beforeRenderResponse><![CDATA[#{javascript:
if (context.getUrlParameter("doRefresh")!=null&&context.getUrlParameter("doRefresh").equals("true")) {
var url = context.getUrl().toSiteRelativeString(context);
url = url.replace("?doRefresh=true","");
context.redirectToPage(url);}
}]]></xp:this.beforeRenderResponse>
This is not a very sophisticated solution, but at least it works :-)
I have a custom control with a field where the user will enter a document ID (not a note ID or UNID, just a unique number). This data source is named document1. When they exit the field, I perform a lookup and display either the document with that ID or a new document in an extlib Dialog control (data source bundleDoc). When bundleDoc is saved, I want to update a log field on document1 to indicate that a bundle document was added.
I can save bundleDoc and close (hide) the dialog but the code in my Save & Close button in the dialog can't "see" document1. I can't refer to it using document1.getItemValueString or by getComponent. The getItemValueString returns and empty string and getComponent throws an error because the return value is null.
I would have posted an image to help visually but I don't have enough reputation yet. :(
What am I missing? Shouldn't I be able to get to document1 from the dialog control since it is on the same XPage?
UPDATE: Two fields on the dialog form have computed default values that use getComponent to get their values from document1. So, at least when the dialog is loaded, it can see document1. Also, bundleDoc is not defined as a data source for the dialog control. I will try that tomorrow to see if it makes a difference.
UPDATE 2: Still not enough reputation to post a picture, but here is some code. This is one custom control that contains a dialog control. document1 is defined as the data source for the custom control and bundleDoc is defined as the data source for the panel in the dialog control that contains the table of fields for the bundle document.
The BundleID field in the dialog control has a computed default value using this:
if (bundleDoc.isNewNote()) {
getComponent("inputBundleID").getValue();
} else {
bundleDoc.getItemValueString("BundleID");
}
The formula for StorageLocationID is similar except that the component is inputStorageTrayID.
This is the code in the Save & Close button:
bundleDoc.save();
var newArr = new Array(document1.getItemValue("WorkLog"));
newArr.push("Added bundle " + document1.getItemValueString("BundleID") + " - " + session.getCommonUserName());
document1.setValue("WorkLog",newArr);
document1.save();
getComponent("dialog1").hide();
The error happens on the document1.save line but it does not get the BundleID from document1 (I set a sessionScope variable to the value of newArr and it showed 'Added bundle - Anonymous'.
It depends on where you have added the datasources. If document1 is set as the datasource of custom control 1 and bundleDoc is the datasource of custom control 2 you can't access them outside of the custom control they're defined in.
If you add document1 as the datasource of your custom control and create the xe:dialog control (containing a panel with the bunleDoc datasource) in the same custom control you should be able to access document1 (and update/ save it) from a button on the dialog.
I think the problem was initially caused by caching issues because it started working the day after I posted the question.
However, I had to do one more thing to get the page to work the way I wanted to. This is the XPage in Designer:
To write a value from the Save & Close button back to the WorkLog field, I had to save the document1 data source before opening the dialog. Then document1 was recognized throughout the Save & Close code and it was saved properly at all times.