How to create in XPages a submit button to discard the current and create a new document? - xpages

I need to create a link on a XPage to refresh the panel with a new document.
The current document must not be saved.
Thank you!

Just create a link with the URL to the page where this link is on, e.g.
<xp:link text="Discard and start over" value="/thepage.xsp?action=newDocument"></xp:link>

you can reinstatiate a data source bound to a panel using the following code. Try running that before you submit.
var c = getComponent("mypanel");
var ds = c.getData();
ds.get(0).refresh();

Related

xpages: how to simulate form's auto launch properties

Is there a quick and easy way to convert forms that have auto launch first attachment and/or launch URL?
I know it can be coded in SSJS but I was just wandering if someone had a quick way of doing this.
Thanks
The following Domino URL command will open an attachment ...
http://Host/DatabaseName/View/DocumentName/$File/fileattachmentname
... where the DocumentName is effectively the lookup value shown in the first column which is sorted.
Add an xp:link control and code it open the attachment (in this example in a new window). For example, the following is an xp:link that could be added in an xp:viewColumn or xp:repeat or any iterator control. In this example the var for the iterator is set to "rowData" and the name for the link is returned from the ListName column and the url to launch the attachment is in the cLinkUrl column.
<xp:link escape="true" id="link1" target="_blank">
<xp:this.text><![CDATA[#{javascript:rowData.getColumnValue("ListName");}]]></xp:this.text>
<xp:this.value><![CDATA[#{javascript:rowData.getColumnValue("cLinkUrl")}]]></xp:this.value>
</xp:link>
Since I wanted the code to be in the xpage, as it opens up either the document or the attachment depending on roles, I ended up adding this to the beforepageload event of the xpage (still need to add the role check to this though):
<xp:this.beforePageLoad>
<xp:executeScript>
<xp:this.script><![CDATA[#{javascript:var url = currentDocument.getDocument().getHttpURL();
var attachmentName = #AttachmentNames();
facesContext.getExternalContext().redirect(url.replace("?OpenDocument","/$File/"+attachmentName+"?OpenElement&target=_new"));}]]></xp:this.script>
</xp:executeScript>
</xp:this.beforePageLoad>

How to change url parameter openDocument to EditDocument from a client side link in XPages

I have a data source called "doc" and a link control on my xpage. The datasource is bound to a document using the url parameter
documentId=914A....&action=openDocument
When I click the link control I want to change the url parameter action to "editDocument" so that my data source goes into edit mode.
I would like this to be a client side solution, so I am thinking it can be done by constructing the url using EL, so something like this.
<xp:link escape="true" text="Edit Mode" id="link5" value="/documentID=#{doc.getUniversalID...}?action=editDocument"></xp:link>
any ideas?
Thanks
Thomas
What about simply changing the location.href by replacing "openDocument" with "editDocument"?
location.href = location.href.replace(\openDocument\g, "editdocument");

How can i get data from another document when i creat a new document on my XPage?

I've start to develop XPage 7 weeks ago, and i have a problem with "getting data".
On my first page i have a view with a lot of documents, and a button who redirect me on a new page, to create a new document. On my first page i can select a document and when i click on the button i put my id document selected on a sessionSCope.
Button script:
var viewPanel=getComponent("viewPanel1");
var docIDArray=viewPanel.getSelectedIds();
var docUID=database.getDocumentByID(docIDArray[0]).getUniversalID();
sessionScope.put("docUID", docUID);
context.redirectToPage("AjoutSuivi");
On my new XPage i want to get some data on my selected document so on clientLoad of the XPage i execute this script:
var docUID = sessionScope.get("docUID");
var doc:NotesDocument = database.getDocumentByUNID(docUID);
getComponent("contactname1").setValue(doc.getItemValueString("ContactName"));
On my database i have a field "ContactName" and on my XPage i have a field contactname1. I have try with "database.getDocumentByID(docUID)" and i'm sure that "database" is the good link of the database.
When i try it, there is nothing on the field contactname1 have u an idea why that's doesn't work ?
So much thank's if you can help me
Yann
PS: sorry for my bad english
Put your code into the event afterPageLoad and it should work (for the execution order of events take a look at XPage Cheat Sheet #1 - The Page Lifecycle).
Y4nn welcome to the XPages club. When you bind a control to a data source it is better to set the value in the data source than in the control. So you write:
document1.getDocument().replaceItemvalue(...)
(picking on a glass now, watch out for correct syntax)

Opening different xpages forms from a view panel

I have an Xpages application that pulls data from another .nsf file. I have a view panel linked to a view in that db. The view has documents with several different forms in it. I want to be able to open each document in it's own form(xpage).
How do I write a computed At Runtime, open selected document using: statement that will select the correct Xpage to present the document.
If you use the Data View component instead of a View Panel, you can compute the pageName attribute, referencing the var attribute to return a different value for each row based on the document that row represents. The flexibility of the Data View component also makes it easier to make your app look more like a modern web application and less like an Excel spreadsheet. As an additional bonus, the mobile theme invokes a renderer that makes each Data View instance look like a native mobile list, so using Data Views instead of View Panels simplifies mobile development.
You have 2 options:
use "use xpage associated with form" and edit the form's property
use a SSJS formula to compute the Form. You provide a variable name in the view control var to access a view row as XSPViewEntry. If the Form is in a view column even one you don't display you use .getColumnValue otherwise getDocument.getItemValueString
Does that work for you?
Maybe this mothed can help you: Unable to get document page name for
Hope this helps
Mark
I had a similar problem today. I use only one form but 3 different xpages for associated with this form. I have 3 different document types in the view. I used rowData the get the type of the document.
try{
var v=rowData.getColumnValue("form");
if(v.indexOf("x")> -1){var page ="x.xsp"}
else if(v.indexOf("y") > -1){var page = "y.xsp"}
else{var page = "z.xsp"}
}catch(e){
var page = "x.xsp"
}
So to your view you can create a column with the value of the form and you can use it.
I have used the extension library Dynamic View control which has an event you can code to get a handle to the NotesViewEntry which was selected. See the demo database page Domino_DynamicView.xsp and the Custom Event Handler tab for an example.
Note, in 8.5.3 (I have not upgraded yet) if you add or edit the eventHandler for onColumnClick it will be added to the XPages source as an xe:eventHandler. It needs to be an xp:eventHandler to work. The way to do it is to copy the code in the source from the exiting event and delete it. Recreate the event and update the code. Then go back into the source and change the tags within the eventHandler to xp:.

Action (button) to open an existing form

I have created a view which displays some informations.
Also, on top of view I created an action bar containing 2actions: New entry & Delete entry. There is also a form called 'formmain', where I have some fields & listboxes where I insert the informations that will appear on the view.
What I want to do and I ask for your help: I want when i click the action button 'New entry', the form called 'formmain' will open/be displayed. Thank you!
You can use the #Compose Formula command for this. Here's an example for your specific form:
#Command([Compose]; ""; "formmain")
I will recommend that you take a look at the Lotus Domino Designer Help database which is part of your Notes installation. It has a lot of useful information including code examples.

Resources