How can I override or add to the XPages NotesXspDocument events? - xpages

I have a custom control into which I pass a data source. The customecontrol.xsp-config file property:
<property>
<description>The src Datasource source data (WIP)</description>
<display-name>Source Datasource</display-name>
<property-name>srcDatasource</property-name>
<property-class>com.ibm.xsp.model.domino.DominoDocumentData</property-class>
<property-extension>
<required>true</required>
<designer-extension>
<category>1. Workflow Parameters</category>
<editor>com.ibm.workplace.designer.property.editors.dataSourcePicker</editor>
</designer-extension>
</property-extension>
</property>
I want to add some logic to the querySaveDocument of this data source with code in the custom control's beforePageLoad event. This logic will add a reader and author names items to the doc as well as some other control values.
How can I get my code added into this event?
Thanks in advance...
/Newbs

You may find a solution here:
http://dontpanic82.blogspot.com/2010/03/xpages-dynamically-binding-document.html
Credits to Tommy Valand...

I have been reading about the computeWithForm property of an xpage. Which can be set to onload, onsave or both.
From Mastering Xpages book:
For XPages Domino Document data sources, if computeWithForm is set, all fields specified in the form are appanded to the document that is being created. Any formulas used to caculate default values are executed and the results are stored in corresponding field.
Maybe it fits your needs
Edit:
Seems there is a bug look at this article:
http://www.thenorth.com/apblog4.nsf/0/17B0E8334B2DCA68852579B400639D62
Not sure if it is fixed by ibm of if there is a workaround.
Edit2:
Not sure but this might help
From Xsnippets.org
It is an answer to another question.

Related

How to open a document in a dynamiccontent control facet from a viewpanel control

I have a dynamiccontent control on a XPage with a facet containing a custom control which has a viewpanel in it. I also have a second facet in the dynamiccontent control containing a custom control which is connected to a document data source.
What I am trying to figure out is when the viewpanel custom control is loaded in the dynamiccontent how do I get the links in the viewpanel custom control to load the dynamiccontent facet containing the custom control connected to the document data source and display the document?
I think the Dynamic Content example in the Extension Library Demo database is self explaining. It use also a view and a document
Well I'ver always found ViewPanels to be very limiting if you want to do anything fancy. I don't think you can easily use any of the built in features. I would personally use a Repeat Control and then have a button that takes the intended document and gets the unid. You can then put that unid into a viewScope variable, change your dynamic content control to the document facet and have that custom control get the unid from viewScope to get the correct document.
I long time ago I did a rather crappy demo that showed a couple of these techniques. https://www.youtube.com/watch?v=GSLAy6U2_3A
The CSS attempt failed there but you should be able to see a repeat control and putting the unid into scope etc. It might help you a little.

xpages dynamically change xpage acl?

I have a basic workflow app, and I am having diffiulty.
In the db ACL, I have all the people and groups involved set to Editor.
In an XPage acl, I am trying to enter a computed value for the name. (a field I have called nextApprover, which is stored on the form/document associated with the xpage.
I've tried
document1.getItemValue("nextApprover");
AND
getComponent("nextApprover").getValue();
both create a runtime error executing the Javascript computed expression.
All I am trying to do is allow the nextApprover the rights to edit the document when it is in their "box" and allow the rest of the users the ability to read it at that particular time. I've looked around for a while now.
Any suggestions?
You can't access the datasource document1 in XPages ACL name calculation because the ACL is first calculated and only later the datasource. That's why you get the JavaScript runtime error.
Here is an alternative to XPages ACL:
Define your datasource document1 with action="openDocument"
<xp:this.data>
<xp:dominoDocument
var="document1"
action="openDocument"
... />
</xp:this.data>
That will open the document by default in READ mode.
Then switch in beforePageLoad event to EDIT mode with context.setDocumentMode("edit") if the current user name is in your field nextApprover:
<xp:this.beforePageLoad><![CDATA[#{javascript:
if (document1.getItemValue("nextApprover").get(0).equals(session.getEffectiveUserName())) {
context.setDocumentMode("edit")
}
}]]></xp:this.beforePageLoad>
You might have to change the if clause depending on what is really in your field nextApprover.
You get better security by using Authors-items on documents instead of XPage ACL.
Try this (if document1 is datasource name):
document1.getValue("nextApprover");
If it does not work with this and you still want to use XPage ACL please post your error and XPage XML source for the ACL part.

xe:breadCrumb Use Without Tree Nodes?

I have an XPages app with a page > sub-page structure that is defined by URL parameters prior to our company's adoption of Domino 8.5.3 UP1. Now that we do have UP1, I've been eyeing up the xe:breadCrumbs control with a little bit of envy. Not being familiar with xe:pageTreeNodes (which I know at least exist thanks to my copy of XPages Extension Library), I figured I'd "phone a friend". I couldn't find much on the topic. My question is two-fold:
How should one implement page tree structure to use properly with the xe:breadCrumbs control?
With my current setup (root page being standard page parameter, sub-page being a second, custom parameter), how easily can I use my setup with xe:breadCrumbs?
At some point, I'm more than willing to cut my losses and just build out a quasi-breadcrumbs element with some computed xp:link controls in a div. Since the opportunity arose, I figured I would check and see if there were some better options. I know this is a little vague, but I think the idea is communicated here.
[Edit:]
I should probably ask if this is something more directly and exclusively used with the xe:navigator. If that's the case, then I may be a little more sad, but a bit less confused.
[/Edit]
Tree nodes are fine. Here is small example. Prerequisites:
all documents are in the same database. Not a big issue, just update href params accordingly.
Document contains fields with ID and Label (subject, title) of parent documents (all levels)
There is view "id" containing only one column sorted by document's id to open it (Domino syntax) - see also: native Domino links and XPages
dds is curent document's datasource
ddsParent is parent document's datasource
<xe:breadCrumbs id="breadCrumbs1">
<xe:this.treeNodes>
<xe:basicLeafNode label="Top document: ${dds.fld_TopLabel}">
href="/id/${dds.fld_TopID}">
</xe:basicLeafNode>
<xe:basicLeafNode label="Sub1: ${ddsParent.fld_Label}">
<xe:this.href><![CDATA[#{javascript:"/0/" + ddsPonuka.getDocument().getUniversalID()}]]></xe:this.href>
</xe:basicLeafNode>
<xe:basicLeafNode label="Current level: ${dds.fld_Label}">
</xe:basicLeafNode>
</xe:this.treeNodes>
You have to alter this for every XPage. Sure, you can make it a custom control with parameters, but you will end up with custom control on every XPage fed by parameters roughly in the same structure.
The best option is to make managed bean configurable in some sort and returning ExtLib tree objects. Then your source will be reduced to:
<xe:beanTreeNode nodeBean="my.bean.Class"></xe:beanTreeNode>
Best example is XPagesExt.nsf bundled with ExtLib distributions.

XPages Open view and open XPage in edit mode

I've told a view to open using an XPage, but how do I open that XPage in edit mode?
I will suggest that you buy and read the Mastering XPages book to learn the basics of handling views and documents in XPages. The book contains material that describes exactly what you are looking for (how to open an XPage in read and edit mode).
I will assume your question relates to the XPage being used to open the selected document from the view and not the view itself as it is not possible to either define an XPage to to launch a view or for a view to be in "Edit Mode"...
When specifying the document data source for an XPage it is possible to define the default action as being Edit Document or Open Document. This sets the "action" property of the data source
The XPage itself has a "readonly" property that can be set to a specific value or computed. This is not tied to a specific data source.
It is possible to add a panel container control to the XPage and set the "readonly" property of the panel. This will allow all the controls inside the panel to be rendered as editable or readonly.
views and xpages cannot be in edit mode, only document data sources can be in edit mode.
In addition to the readonly properties that Peter mentioned:
It is possible that a custom control got its own data source while the one from a parent (e.g. the xpage) is in edit mode. That's the mistake i make often while binding controls to data fields.

How do you use the Selected property of the navigator?

I've spent days trying to figure this out and I give up.
I am a LotusScript programmer and have been trying to learn XPages. All of the examples and sample programs I've studied only touch on pieces of this.
Can someone explain to me step by step how to use the Selected property of the Extension Library Navigator control?
I have created my own custom control based on the layout control from the Extension Library and created a custom property called navigationPath. I also created a navigator custom control that has 5 Page Link Nodes. In the "Selected" property of each Page Link Node, I put the following SSJS:
if(compositeData.navigationPath == "/Home/ApplicationPool"){
return true
}else{
return false
}
/Home/ApplicationPool corresponds to the value I put in the "Selection" property of the particular Page Link Node.
In each layout custom control, I set the "navigationPath" property to compositeData.navigationPath.
What did I miss?
there is a selected and selection property and they mean very different things and can't be used at the same time. In the code example in your question above you are using the selected property which is the wrong one in this case.
Your treeNodes in the navigator should be setup to use the selection property, this is a RegEx value that is used to see if it matches the value passed into the application layout via the custom property.
<xe:navigator id="navigator1" expandable="true" expandEffect="wipe">
<xe:this.treeNodes>
<xe:pageTreeNode label="nodeName" page="/page.xsp" selection="/Home/ApplicationPool" />
</xe:this.treeNodes>
</xe:navigator>
As you can see you don't need to use any SSJS to evaluate a true/false outcome. Just match the value in the treeNode to the one in the XPage's applicationLayout control.
If your using tabs in the layout titleBar then you can set a selection property there also that uses the format /Home/.* which will make that tab highlighted for every XPage that have /Home/ at the start of it's navigationpath custom property. Don;t forget it is RegEx so any valid RegEx statement can be used here adding more power to this particular property.
For the tree nodes in the navigator control you define the name of the xpage to open and then the related selection. Example:
<xe:pageTreeNode page="/text.xsp" selection="/Home/Test" label="Test page">
</xe:pageTreeNode>
For the individual xpages using the applicationLayout you define a value for navigationPath. If this value matches an entry in one of the tree nodes the naviagor control, then the corresponding menu item will be highlighted in the browser. The best way to define the value of the navigationPath is by using a custom property (as you are using). Here's an example of that:
<xe:applicationLayout id="applicationLayout1">
<xe:this.configuration>
<xe:oneuiApplication navigationPath="${javascript:compositeData.navigationPath}" ...
You can see examples of using all this in the Extension Library Teamroom and Discussion templates.
Based on my explanation on how to use it, I can see that you are not using the selection property on the navigation control correct. You just need to define a unique value for each tree node (which then will be used if it matches navigationPath on the individual xpages).
So for your specific example change your selection property to just return: "/Home/ApplicationPool"

Resources