xPages: redirect to home when dialog closes - xpages

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 = "noreply#belairdirect.com";
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

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.

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

Related

XPages appendDocLink on Anonymous User Error

I am attempting to replace my 'traditional Notes' User Name and Password Request form with one designed in XPages, mainly because the #SendMail Formula no longer works with Firefox or Chrome.
Anonymous users are to complete an XPage Form, hit a submit button which then sends an email to our support team, which is to include a Doc Link back to an internal Notes form of the same document, - I don't want to change this internal form as there is lots of lotusscript programming associated with it for processing.
I have the XPage marked as Available to Public Access as is the form associated with it. I also have ComputeWithForm set to both.
I can access the data document components e.g. append to the mail rtf body using doc.getItemValueString("field"), but I cannot do the same with appendDocLink it appears to fail due to access problems. If I set Anonymous to Manager access in the ACL the Doc link is appended.
<xp:button value="Submit" id="button1" style="margin-top:50.0px">
<xp:eventHandler event="onclick" submit="true" refreshMode="complete" immediate="false" save="false" id="eventHandler1">
<xp:this.action>
<xp:actionGroup>
<xp:saveDocument var="document1"></xp:saveDocument>
<xp:executeScript>
<xp:this.script><![CDATA[#{javascript: if(document1.isNewNote()){document1.save();}
var doc:NotesDocument = document1.getDocument(true);
var receiverEmail = "Support Requests";
var requestor = "xyz#company.co.uk";
db = sessionAsSignerWithFullAccess.getCurrentDatabase();
var memo = db.createDocument()
memo.appendItemValue("Form","Memo");
memo.appendItemValue("Principal","Company#NotesDomain");
memo.appendItemValue("From",requestor);
memo.appendItemValue("INetFrom",requestor);
memo.appendItemValue("DisplaySent",requestor);
memo.appendItemValue("SMTPOriginator",requestor);
memo.appendItemValue("Subject","NEW: Name & Password Request for "+getComponent("reqCompany1").getValue());
var rtitem:NotesRichTextItem = memo.createRichTextItem("Body");
rtitem.addNewLine();
rtitem.appendText("A new Name & Password Request has been logged by "+getComponent("reqFirstName1").getValue()+" " + getComponent("reqSecondName1").getValue()+" of "+ getComponent("reqCompany1").getValue());
rtitem.addNewLine();
rtitem.appendText("Click the Doc link to action it. ");
rtitem.appendDocLink(doc);
memo.send(receiverEmail);}]]></xp:this.script>
</xp:executeScript>
<xp:openPage name="/UserNandPSubmitted.xsp"></xp:openPage>
</xp:actionGroup>
</xp:this.action>
</xp:eventHandler>
</xp:button>
The following errors occur.
com.ibm.jscript.InterpretException: Script interpreter error, line=25, col=8: [TypeError] Exception occurred calling method NotesRichTextItem.appendDocLink(lotus.domino.local.Document)
null
NotesException: Notes error: You are not authorized to perform that operation
lotus.domino.local.RichTextItem.appendDocLink(Unknown Source)
lotus.domino.local.RichTextItem.appendDocLink(Unknown Source)
Any help would be greatly appreciated.
Make sure Anonymous user can access the default view of the database - so make it accessible to public access users. appendDocLink() method requires this view in order to append doc link to RT item.

XPages - Open document in new tab with xp:openPage

I have this piece of code on my system, inside a xp:viewColumn:
<xp:eventHandler event="onclick" submit="true"refreshMode="complete">
<xp:this.action>
<xp:actionGroup>
<xp:executeScript>
<xp:this.script><!CDATA[#javascript:sessionScope.retornarPara=view.getPageName()}]]>
</xp:this.script>
</xp:executeScript>
<xp:openPage target="openDocument" documentId="#javascript:entry.getDocument().getUniversalID()}">
<xp:this.name>
<![CDATA[#{javascript:return "/xsp_arma.xsp"}]]>
</xp:this.name>
</xp:openPage>
</xp:actionGroup>
</xp:this.action>
</xp:eventHandler>
I need that the page opened by the xp:openPage be in a new tab. Is that possible? Do I need to use other type of code to do that?
Thanks.
If this event handler is inside a xp:link you can set the target of the link in all properties:
Instead of the simple action you can use ssjs
With the following url you can open a specified document:
application.nsf/xpage.xsp?action=openDocument&documentId=DOCUMENT_ID
var path = facesContext.getExternalContext().getRequest().getContextPath();
var xpage = "byTag.xsp"
var fullpath = path + "/" + xpage;
var documentID = "**"
var url = fullpath + "?action=openDocument&documentId="+ documentID
view.postScript("window.open('" + url + "')")
First you'll get the path of your current database then you can specify the xpage which will show the document and then youl can pass the documentID like #javascript:entry.getDocument().getUniversalID()}
With a call of csjs you can open the page in a new tab

Using JQuery to mask input fields. When I refresh a panel that contains those fields the masking stops working

I have several phone number fields that use jquery masking to format the input. See the code below. The fields work great until a combo box change above refreshes a panel that contains those fields. Once the refresh happens my masking stops working.
Any idea why and how to prevent this from happening?
<xp:scriptBlock id="scriptBlock7">
<xp:this.value><![CDATA[
jQuery(function($){
x$("#{id:dayPhone1}").mask("(999) 999-9999? x 9999999", {placeholder : " " } );
x$("#{id:eveningPhone1}").mask("(999) 999-9999? x 9999999", {placeholder : " " } );
x$("#{id:cellular1}").mask("(999) 999-9999? x 9999999", {placeholder : " " } );
});
]]></xp:this.value>
</xp:scriptBlock>
The jQuery is only run one time. It manipulates the DOM to give the mask effect. Once you run a partial refresh the original DOM is returned to the user and the mask is no longer in effect.
When the partial refresh happens the jQuery code does not know to apply itself back to the mask again. You have a number of choices, but the best is probably:
In the onComplete event of the partial refresh you can call the mask code again to reapply the "Mask". What I don't know is if the mask code will reset the fields or honor the values therein. I that is the case then take a look at the plugin code and see what options you have.
<xp:button value="Label" id="button1" styleClass="startLoginProcess" style="display:none">
<xp:eventHandler event="onclick" submit="true" refreshMode="partial" refreshId="somethingHere"
onComplete="applyMaskCodeAgainHere">
</xp:eventHandler>
</xp:button>
To improve the code above because it looks like you are applying the same mask I suggest using a class selector and simplifying your code to look more like this:
<xp:scriptBlock id="scriptBlock7">
<xp:this.value><![CDATA[
jQuery(function($){
$('.phoneMask').mask("(999) 999-9999? x 9999999", {placeholder : " " } );
});
]]></xp:this.value>
</xp:scriptBlock>
put a styleClass="phoneMask" on your field :)
Is your scriptBlock also on the panel that is being refreshed? It needs to be in order for the the mask to be reapplied to the fields after the refresh.
You can remove the mask and reset it...
$(`#${id:dayPhone1}`).val(newPhoneValue).unmask().mask('(00) 00000-0000', {clearIfNotMatch: true});
This worked for me and should solve your problem!
TLDR: .unmask() before .mask()

Open NotesURL via redirect

I have a repeat-control which generates me a list of links to documents in a different database.
Special on this task is that the XPage runs in the notes internal browther (NOT XPniC) and open the documents as real notes documents in the notes client (NOT Xpages). so far every thing works fine.
Now I want too check if the document exists before I open the document.
My solution is an xAgent which check if the document exists and redirect to the NotesURL but I get the following error:
Error source
Page Name:/xaOpenDocument.xsp
Exception
Error while executing JavaScript action expression
Script interpreter error, line=25, col=43: Error calling method 'redirect(java.lang.String)' on java class 'com.ibm.xsp.domino.context.DominoExternalContext'
notes://SERVER01#SRV#DE#OU#MyCompany AG/__C1257B6B002A0472.nsf/0/C1257B6B002A0472C12574CD0024E6B9
The link to the xAgent looks like this:
http://SERVER02/dev/release_4/test_xui.nsf/xaOpenDocument.xsp?dbServer=SERVER01%2FSRV%2FDE%2FOU%2FMyCompany+AG&dbPath=dev%5C%5Crelease_4%5C%5Ctest_adr&docUNID=C1257B6B002A0472C12574CD0024E6B9
The xAgent code looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core" rendered="false">
<xp:this.afterPageLoad><![CDATA[#{javascript:var server:string = context.getUrlParameter("dbServer");
var db:string = context.getUrlParameter("dbPath");
var unid:string = context.getUrlParameter("docUNID");
var url:string = "";
var targetDB:NotesDatabase = session.getDatabase(server,db);
var doc:NotesDocument = targetDB.getDocumentByUNID(unid);
if(doc == null){
requestScope.put("targetDocUNID",unid);
println("xaOpendocument targetDocUNID: " + unid);
requestScope.put("dbServer",server);
println("xaOpendocument dbServer: " + server);
requestScope.put("dbPath",db);
println("xaOpendocument dbPath: " + db);
requestScope.put("targetError","Dokument konnte nicht geƶffnet werde. \n Document wurde verschoben oder entfernt.");
println("xaOpendocument URL: xpErrorMessage.xsp");
context.redirectToPage("xpErrorMessage.xsp");
}else{
url = sessionUser.getDocumentURL(targetDB,unid);
println("xaOpendocument: Dokument wurde gefunden... Umleiten!");
println("xaOpendocument URL: " + url);
facesContext.getExternalContext().redirect(url);
}}]]></xp:this.afterPageLoad>
</xp:view>
The Serverconsole shows me the following error lines:
30.07.2013 11:17:47 HTTP JVM: xaOpendocument: Dokument wurde gefunden... Umleiten!
30.07.2013 11:17:47 HTTP JVM: xaOpendocument URL: notes://SERVER02#SRV#DE#OU#MyCompany AG/__C1257B6B002A0472.nsf/0/C1257B6B002A0472C12574CD0024E6B9
30.07.2013 11:17:47 HTTP JVM: com.ibm.xsp.webapp.FacesServlet$ExtendedServletException: com.ibm.xsp.exception.EvaluationExceptionEx: Error while executing JavaScript action expression
30.07.2013 11:17:47 HTTP JVM: CLFAD0134E: Exception processing XPage request. For more detailed information, please consult error-log-0.xml located in F:/Lotus/data/domino/workspace/logs
I hope for some useful help - I wasted already to much time on this problem. I thought it should be simple. :/
Your problem is that you are trying to do a server side redirect.
instead of
facesContext.getExternalContext().redirect(url);
try this
view.postscript('window.location.href="+url+"')
To make the redirect client side instead
The problem is that the XPages Engine does not know the notes:// url format. Internally the given URL parameter will be converted with java.net.URL, and this throws an error.
Maybe you can send your own HTTP headers instead for the redirection to the notes:// URL.
EDIT:
This should do the trick:
}else{
url = sessionUser.getDocumentURL(targetDB,unid);
println("xaOpendocument: Dokument wurde gefunden... Umleiten!");
println("xaOpendocument URL: " + url);
var resp:com.ibm.xsp.webapp.XspHttpServletResponse = facesContext.getExternalContext().getResponse();
resp.setStatus( 302 );
resp.addHeader("Location", url );
facesContext.responseComplete();
}
I figured it out.
The main problem was to call CSJS in backend functions for the redirect., becourse ssjs facesContext.GetExternalContext().redirect(url) could not handle my notes url (notes://...).
One hint by Frederic Norling was to use the view.postscript('window.location.href="+url+"'), but this function is only supported with Notes/Domino 8.5.3+ (sadly we use 8.5.2).
The enlightenment comes with my discovery of the EventHandler- Event "onComplet()".
Now I create a Link component with a onClick()- Event:
<xp:link escape="true" id="link1" tabindex="-1" style="font-weight:bold">
<xp:this.text>MyLink</xp:this.text>
<xp:eventHandler event="onclick" submit="true"
refreshMode="partial" refreshId="refreshCheckDoc">
<xp:this.action>
<![CDATA[#{javascript:<some code for checking my URL Target and write the URL in a requestScope variable when the target exist else I write a propper ErrorMessage in a requestScope Varaible>]]></xp:this.action>
On my XPage I have a panel with the id "refreshcheckDoc" an on this Panel I have two hidden fields. The first Field get his value from the requestScope.url the other get the requestScope.ErrorMessage. On the onClick()- Event I attached the onComplet()- Event.
In the onComplet()- Event I check the content of the two fields. Is the url empty AND the errorMessage I do nothing. If I have the url I call window.location.redirect(url), if I have the ErrorMessage I use the alert() function to inform the user about the error.
Thanks for all Your help. I hope this short description is helpful for others, too.

Post status update to IBM Connections using extlib

I am trying to post an update i.e. a status message to IBM Connections using the extlib.
I have used the extlib with connectionsLTPA endpoint which works really well for getting the communities list. However I wish to add functionality to update the users status.
So far I have tried using
<xp:this.data>
<xe:connectionsData var="connectionsData1"
endpoint="connections" serviceUrl="/profiles/atom/mv/theboard/entry/status.do?email=#{userBean.email}">
</xe:connectionsData>
</xp:this.data>
and then in the event handler
var sb = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>" +
"<author><name>#{userBean.displayName}</name></author>" +
"<entry xmlns=\"http://www.w3.org/2005/Atom\">" +
"<content type=\"html\">" +input + "</content>" +
"<category scheme=\"http://www.ibm.com/xmlns/prod/sn/type\" term=\"status\" />"+
"</entry>\r\n";
var output = #{connectionsData1}.post(null, sb, "xml");
however this throws an error trying to call post on the binded data point.
Anybody able to point me in the right direction?
Thanks
I have found that implementing the sbt by doing the follwing:
<xp:button id="button2">
<xp:this.value>Update my status</xp:this.value>
<xp:eventHandler event="onclick" submit="true"
refreshMode="partial">
<xp:this.action><![CDATA[#{javascript:try {
var svc = new sbt.ConnectionsService("/profiles/atom/mv/theboard/entry/status.do?email=" +userBean.email);
var sb = new java.lang.StringBuilder();
sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
sb.append("<entry xmlns=\"http://www.w3.org/2005/Atom\">");
sb.append("<category scheme=\"http://www.ibm.com/xmlns/prod/sn/type\" term=\"entry\"/>");
sb.append("<category scheme=\"http://www.ibm.com/xmlns/prod/sn/message-type\" term=\"status\"></category>");
sb.append("<content type=\"text\">");
sb.append(getComponent("inputText1").getValue());
sb.append("</content>");
sb.append("</entry>");
var msg = svc.put(null, sb.toString(),"xml");
var msg = "updated users profile status";
#WarningMessage(msg)
} catch(e) {}
}]]></xp:this.action>
</xp:eventHandler>
</xp:button>
The reason it wasn't working correctly is that the atom feed needed to be declared as an entry. This article in the connections doc for 2.5 http://publib.boulder.ibm.com/infocenter/ltscnnct/v2r0/index.jsp?topic=/com.ibm.connections.25.help/r_api_prof_update_photo.html explains the required parts of the xml atom document.

Resources