How do I create a messagebox to inform successful save in xpages? - xpages

I've set my button to 'Submit'. The XPage is set to stay on the same page if save is successful. How do I create a messagebox to inform user the save is successful?

There are a number of options you can consider. A msgbox is the least desirable.
You could add an information message on top of the form that either fades after a few seconds or on change. The custom control would show when you set a viewScope variable (e.g. viewScope.saveSuccess ) and have a visibility formula for it. It also would register an event listener to hide when a field is altered. You also could consider redirecting to a different page.

This post already asks a similar question to do with how to call a client side script from server side, could be useful.
client message after SSJS routine how?

Here are two examples that I have used as inspiration to create a custom control for error messages and for info messages such as what you are asking for:
http://openntf.org/XSnippets.nsf/snippet.xsp?id=ssjs-form-validation-that-triggers-errormessage-controls
http://lotusnotus.com/lotusnotus_en.nsf/dx/xpages-tip-a-simple-cc-for-prompting-ssjs-messages-to-ui....htm

The easiest way to call csjs after running ssjs is to add code the event handler's onComplete event. The onStart, onComplete, and onError events run client side js before or after your ssjs, but are only executed during a partial page refresh.

The simplest way is to add this line of code (or the CSJS you prefer) in the postSaveDocument event:
view.postScript('alert("Document saved")');

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".

Saving the states of JavaFX controls on exit

I have a bunch of control objects (TextBoxes, to be precise) that get injected into my code using the #FXML annotation during the FXML load.
I would like to save the states of these controls, specifically the text values, when the user closes the Scene by clicking the close box on the title bar.
However, when I trap the CloseRequest event in an OnCloseRequest handler I find that the values of the control variables are null (the original injection works, so this is something that happens in between the loading of the FXML and the calling of OnCloseRequest).
Can anyone explain this behavior and/or suggest how I can get the functionality that I want?
TIA
onCloseRequest is
Called when there is an external request to close this Window. ...
(from Javadoc). One of the meanings of "external request" is when you close the window through OS native window close button. The closeRequest event is not triggered through the programmatic stage.close() or stage.hide() calls. So consider to handle onHiding or onHidden events.
Otherwise post your OnCloseRequest handler code.

combobox onchange with partial update doesn't fire in new document mode

In my Custom Control I have SSJS for a combobox onchange event to update an element using partial update.
The event is not fired when I'm in new document mode but fires when in edit mode.
I've tried other combinations such as Full Update, other events but it seems like Partial update is not working when in New Document mode.
Am I missing something here?
Using examples from: xpageswiki.com
Please advice
/Mike
I'll need to see the block for your radio button from your page's XML source.
These types of issues are sometimes caused by a bad event handler. In particular, depending on how you use Eclipse, there may be more that one block due to bugs in DDE. If you find more than one block, remove all but one, and try again. When this happens to me, I normally remove all blocks, then use the DDE UI to manually add the code and settings back.
When having required fields on the form and they are not filled in the event will not fire due the JSF phase. Setting the Server option "Process data without validation" to True will prevent the JSF to validate and continue with the event.

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.

How to avoid use of timer when using TThread to communicate with UI thread

I have a TThread which receives and sends to a device on a COM port. After I read the data, I want to activate the GUI (not in the same thread) using Synchronize(function name). However, when I call the GUI's form function to perform a button click, I get an access violation. I checked to see if the form's value is null and it is not, since this would be an obvious reason for access violation. Right now, I am setting global flags and using a timer that continuously checks to see if a certain condition is met and if so, then I fire off the button click event in that form. That seems to be the only way to avoid getting the access violation.
I really don't like timers so is there a way to avoid having to use a timer on the form?
You can post a message to the window in question. The timer works in a similar manner. It just fires off a windows message inside the form. You obviously have a handle to the window.
CWnd::PostMessage(...) Don't use send message, it gets processed inline and could cause your thread to stop working.
Typically when you have a worker thread that attempts to access Guithread, they conflict. It's been a while since I've used MFC and threading but that's what I remember. I believe it's documented to work that way.
I found the problem. I thought I was checking if my Form was null, but I was not. I fixed it making sure the form I was referencing is not null.
Edit: Turns out that one of the forms that is called when I call Fbutton1Click() is Modal so it blocks my thread. I ended having to go back to a timer to call the button click instead.. oh well.

Resources