191 Lotus blogs updated hourly. Who will post next? Home | Blogs | Search | About 
 
Latest 7 Posts
An apparent theme: application agnosticism
Fri, Aug 19th 2016 2
Sessions for #MWLUG2016
Fri, Jul 1st 2016 5
Can you hear me now? Life without #HearingLoss
Tue, May 10th 2016 1
Austin, Texas hosts #MWLUG2016 in August
Wed, Apr 6th 2016 3
Orphan #Java class files in the Local folder in #XPages
Thu, Mar 31st 2016 2
An agent to change field values to help in #XPages
Tue, Mar 22nd 2016 2
Copying property definitions for custom controls in #XPages
Thu, Mar 10th 2016 1
Top 10
Simple view without links in #xpages
Fri, May 2nd 2014 5
Showing a database in a panel in #IBMNotes
Tue, Jul 22nd 2014 5
Sessions for #MWLUG2016
Fri, Jul 1st 2016 5
Sample database for #Excel exporting from #XPages
Mon, Feb 24th 2014 4
Exporting from #XPages to Excel without Excel, Part 2
Thu, Sep 26th 2013 4
Dirty pages and keeping users on them in #XPages
Wed, Apr 16th 2014 3
Are you sure? Asking for confirmation in #XPages
Wed, Sep 17th 2014 3
What “They” Never Tell You About Owning a Business #MWLUG2015
Wed, Aug 19th 2015 3
Austin, Texas hosts #MWLUG2016 in August
Wed, Apr 6th 2016 3
Exporting from #XPages to Excel without Excel, Part 1
Wed, Sep 25th 2013 2


Are you sure? Asking for confirmation in #XPages
Twitter Google+ Facebook LinkedIn Addthis Email Gmail Flipboard Reddit Tumblr WhatsApp StumbleUpon Yammer Evernote Delicious
David Navarre    

Often, we want to confirm with the user that they actually want to save or submit a document in XPages. I thought it would be very simple to customize the server-side simple action ‘confirm’ to include client-side data that the user had just entered, but that was not yet saved to disk.

So, I had what I thought was some simple and straight-forward SSJS:

<xp:confirm>
    <xp:this.message><![CDATA[#{javascript:var baseText = "Are you sure that you want to set the exchange rate for ";
        var effectiveDate = getComponent("effectiveDate").getValue().toString();
        var localCurrency = getComponent("localCurrency").getValue();
        var exchangeRate = getComponent("exchangeRate").getValue();
        return baseText + localCurrency + " to " + exchangeRate + " as of " + effectiveDate + "?"; }]]>
    </xp:this.message>
</xp:confirm>

I posted my question on StackOverflow and Paul Withers pointed out that I wasn’t going to get what I was looking for….

You’re computing SSJS to pass to a CSJS confirm() message. I would expect it to display values at the last refresh, not values just entered by the user. If you want the latest values, I think you’ll need to access them via CSJS.

So, I made the classic mistake of failing to know whether I and my data were client-side or server-side. Thus, my getComponent commands were getting a handle to the last version of the server-side component, not what the user just entered on the client-side. So, I needed to move back to the client-side to display client-side values. Fortunately, I remembered that if your client-side javascript evaluates to false, the server-side script never executes.

<xp:eventHandler event="onclick" submit="true" refreshMode="complete"
        immediate="false" save="true" id="eventHandler3">
        <xp:this.script><![CDATA[var baseText = "Are you sure that you want to set the exchange rate for ";
            var effectiveDate = document.getElementById("#{id:effectiveDate}").value;
            var localCurrency = document.getElementById("#{id:localCurrency}").value;
            var exchangeRate = document.getElementById("#{id:exchangeRate}").value;
            return window.confirm (baseText + localCurrency + " to " + exchangeRate + " as of " + effectiveDate + "?");]]>
        </xp:this.script>
        <xp:this.action><![CDATA[#{javascript:exchangeRateDoc.save();
    context.redirectToPage("/pro_exchangeRate_view.xsp")}]]>
        </xp:this.action>
</xp:eventHandler>

The key to the client-side javascript is to make sure you return the value of that window.confirm at the end. In my initial attempt, I didn’t return the value and my testers pointed out to me that my ‘Are you sure?’ was just taunting my users. It would ask the question, but it ignored the response. Clicking OK would save it, as intended, but clicking Cancel would ALSO save it! Talk about ignoring user input!

Hopefully, my mistake will prove instructive in your attempts to find your way in XPages…..




---------------------
http://lostinxpages.com/2014/09/17/are-you-sure-asking-for-confirmation-in-xpages/
Sep 17, 2014
4 hits



Recent Blog Posts
2
An apparent theme: application agnosticism
Fri, Aug 19th 2016 9:55a   David Navarre
A
5
Sessions for #MWLUG2016
Fri, Jul 1st 2016 11:54a   David Navarre
A
1
Can you hear me now? Life without #HearingLoss
Tue, May 10th 2016 11:50p   David Navarre
A
3
Austin, Texas hosts #MWLUG2016 in August
Wed, Apr 6th 2016 4:46p   David Navarre
A
2
Orphan #Java class files in the Local folder in #XPages
Thu, Mar 31st 2016 3:56p   David Navarre
A
2
An agent to change field values to help in #XPages
Tue, Mar 22nd 2016 1:14p   David Navarre
A
1
Copying property definitions for custom controls in #XPages
Thu, Mar 10th 2016 1:11p   David Navarre
A
2
Pause to breathe: a note from Lotusphere ’16
Mon, Feb 1st 2016 4:11p   David Navarre
A




Created and Maintained by Yancy Lent - About - Planet Lotus Blog - Advertising - Mobile Edition