read in properties on beforepageload - xpages

I would like to read a value from a properties file in the beforepageload event. unfortunately I load the properties file as a variable via a theme but ofcourse this does not work because it is not available yet.
Is there anoter way to read in the file via SSJS ?

You can add the properties file as a "bundle" to the XPage's resources:
<xp:this.resources>
<xp:bundle src="/XYZ.properties" var="XYZ"></xp:bundle>
</xp:this.resources>
and directly get any of its property values with:
var propvalue = XYZ.propkey;

Related

How can I readonly attribute in Backoffice config.xml dynamic

I want to set/unset readonly attribute of certain field in backoffice editor area based upon the property that is defined in local.properties.
I tried doing following:
<editorArea:attribute qualifier="xyz" readonly="spring.getBean('configurationService').getConfiguration().getBoolean('make.me.readonly')"/>
but there was schema validation error and also it didn't change the field attribute.
First you need to register "configurationService" so that it could be used in config.xml.
By default only the services mentioned in,
platformbackoffice.available.bean.names.for.spel=labelService,enumerationService,exceptionTranslationService,backofficeTypeUtils can be used within config.xml.
To include "configurationService" add the below piece of code to your backoffice-spring.xml.
<cng:list-extender bean="fixedBeanResolver" property="availableBeanNames">
<cng:add value-type="java.lang.String">
<value>configurationService</value>
</cng:add>
</cng:list-extender>
And then make the service call from config.xml,
<editorArea:attribute qualifier="xyz" readonly="#configurationService.getConfiguration().getBoolean('make.me.readonly')"/>

What is that complex property "All properties > data > properties" good for?

This is just out of curiosity: looking for some other type of property inside an xpage I stumbled upon "All properties > data > properties". This is a complex prop, multiple parameter elements can be added in sets of name > value pairs.
I tried to add a sample parameter here resulting in
<xp:this.properties>
<xp:parameter
name="param"
value="val">
</xp:parameter>
</xp:this.properties>
Rendering that page in a browser shows no changes at all, neither in the page's html source nor somewhere in the http headers, DOM trees etc.
Can anyone shed a light what this property set could be used for?
The xp:view this.properties accepts xsp.properties options like the Xsp Properties editor in an application in Domino Designer, and like the options in the file C:\Domino\data\properties\xsp.properties.sample
For example:
<xp:this.properties>
<xp:parameter name="xsp.client.validation" value="false"></xp:parameter>
</xp:this.properties>
will disable client-side validation for the current XPage, so that only server-side validation occurs.
Some options will be ignored when set in the xp:view on an XPage, e.g.
xsp.theme=oneuiv3.0.2
can only be set in the application xsp.properties or in the server-wide xsp.properties, and will be ignored if it is set in the per-XPage xp:view this.properties.

Binding data to a single document from multiple custom controls

I have an Xpage with multiple custom controls that make up a form. When I click the submit button I get a multiple documents saving the multiple custom control data as a separate document.
I have the data sources configured at the custom control level.
How can I make it that all the custom control save the data to one single document?
Thanks,
Just put them on the XPage. If you use a variable name (e.g. for a datasource, a dataContext etc), the runtime will just look outwards from the current component in the hierarchy to find the relevant object. If you're having problems thinking of the XML source code in a three-dimensional way, the Outline view is good for this.
So from within a Custom Control, you can reference a datasource on the XPage, as long as it is defined in an ancestor of the custom control on the XPage or is a previous sibling. So in the structure below, document1 will be accessible from anywhere in the ccFriends custom control.
<xp:view xmlns:xp="http://www.ibm.com/xsp/core"
xmlns:xc="http://www.ibm.com/xsp/custom">
<xp:this.data>
<xp:dominoDocument var="document1" formName="Profile">
</xp:dominoDocument>
</xp:this.data>
<xc:ccFriendsAlt></xc:ccFriendsAlt>
You can also pass the data source object as a custom property to the custom control if you can't follow Paul's suggestion of keeping the same variable name for your data source.
http://lpar.ath0.com/2013/04/22/passing-document-data-objects-to-xpages-custom-controls/

How do I properly use a Custom Control's "Datasource Picker editor"?

I'm passing a doc datasource into a Custom Control using a property defintion named docDatasource and set to a datatype com.ibm.xsp.model.domino.DominoDocumentData. Just by chance I stumbled upon an editor type named "Datasource Picker". Sounded promising, so I set it to use for m prop definition.
Upon binding the CC into my Xpage - where my doc DS is defined - I indeed can use the picker to choose my datasource ,just as I had expected. But then building the Xpage code I receive an error saying
The value of the property docDatasource cannot be primitive.
So obviously the datatype and the editor don't go along well. There's no harm done really, but I'm curious to learn what else this editor could be used for.
What to do with name of the data source passed to custom control parameter: retrieve its object by simple binding #{requestScope[compositeData.docDatasource]}.
That will return your data source and you can use this binding where needed. Or store it inside local variable and use it instead.
I dont know where you went wrong.
Here is xpage source:
<xp:this.data>
<xp:dominoDocument var="document1" formName="asdf" action="openDocument" documentId="08f6"/>
</xp:this.data>
<xc:doccc dds="#{javascript:document1}"/>
and custom control:
<xp:label id="label1">
<xp:this.value><![CDATA[#{javascript:compositeData.dds.getItemValueString("fl_name");}]]></xp:this.value>
</xp:label>
with custom control property named dds, type com.ibm.xsp.model.domino.DominoDocumentData and editor DataSourcePicker.

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.

Resources