Ben Dubuc
Ben Dubuc

Reputation: 523

xPages: redirect to home when dialog closes

I have a contact form where I use the email bean found on OpenNTF snippets to send the email out. That part works great.

Once the email is sent, I am showing a dialogbox with a little message to let the user know that the message was sent. What I would like to do, and can't figure out, is to redirect the user to the homepage once he hits the close button on the dialog.

Here's the code in the button:

<xp:button id="button1" value="Send">
    <xp:eventHandler event="onclick" submit="true"
        refreshMode="complete">
    <xp:this.action><![CDATA[#{javascript:try{
    //var sendTo = document1.getItemValueString("SendTo");
    var sendTo = AppConfig.getAppEmailAddress();
    //var subject = document1.getItemValueString("Subject");
    var subject = "Belair Docum: " + document1.getItemValueString("category") + " - " + document1.getItemValueString("Subject");
    //var senderEmail = "[email protected]";
    var senderName = userBean.abbreviatedName;
    emailBean.setSendTo(sendTo);
    emailBean.setSubject(subject);
    emailBean.setSenderEmail(senderName);
    emailBean.setSenderName(senderName);
    emailBean.setDocument(document1);
    emailBean.setFieldName("Body");
    emailBean.setBannerHTML("<p>Email sent from belair Docum 2.0</p><hr>");
    //emailBean.setFooterHTML("<hr><p>Email sent from belair Docum 2.0</p>");
    emailBean.send();

    var d = getComponent('dialog1');
    d.show();
}catch(e){
    print(e.getMessage());
}}]]></xp:this.action>
        </xp:eventHandler>
</xp:button>

I tried to put this in the Dialog's Dojo onClose event, but it doesn't work:

window.location.pathname = "/home.xsp"

Can it be a refresh issue, or I am not using the proper event, or I need to use different code?

Thanks :D

Upvotes: 1

Views: 153

Answers (2)

Ben Dubuc
Ben Dubuc

Reputation: 523

Steve, I ended up with a very simple solution...

In the onHide event of the dialog (not the onClose), I have put this little client side snippet:

path = location.pathname.split('.nsf')[0] + '.nsf/';
window.location.href = path + "/home.xsp";

And that works. The button still requires a partial refresh to trigger the dialog, and I have put it on the dialog itself (dialog1).

I'll give your solution a try, though. :D

Upvotes: 0

Steve Zavocki
Steve Zavocki

Reputation: 1840

Ben,

This would be a good case to use view.postScript() Add this to the end of your SSJS code, and put clientside javascript in there to redirect to wherever you want. It will only run at the completion of your serverside code.

Upvotes: 1

Related Questions