XPages: context.getUser().getRoles() working sporadically - xpages

This is weird.
I've logged in here as Admin Mustermann, but when I try to determine the user's roles, I get nothing:
current user:
<xp:text
escape="true"
id="computedField4"
value="#{javascript:context.getUser()}">
</xp:text>
roles:
<xp:text
escape="true"
id="computedField5"
value="#{javascript:context.getUser().getRoles()}">
</xp:text>
And if I open my XPages Debug Toolbar, it tells me I'm Anonymous.
This is my ACL which confirms Admin Mustermann should have at least three roles:
I'm stumped.

I'd prefer to use database.queryAccessRoles(session.getEffectiveUserName()) instead of using the context.
I created a bean for getting a lot of ACL and user informations as a snippet: http://openntf.org/XSnippets.nsf/snippet.xsp?id=sysinfouser-acl-info-custom-control-java-bean

Oddly, #UserRoles is more reliable. Try using this instead:
roles:
<xp:text
escape="true"
id="computedField5"
value="#{javascript:session.evaluate("#UserRoles");}">
</xp:text>
We had a problem with context.getUser().getRoles() failing when using XPages in the Notes Client on local when not disconnected. You can reconfigure your location document in some manner to avoid this, but I never figured that one out. Using the old formula language stuff was suggested during a PMR and it works even if the coinfiguration is, like mine, wrong.

Related

Loading Indicator Page Full Refresh in XPages

One of my XPages there are mo many design elements. The page takes time to load more than expected according to connection speed. I would like to create an indicator to show the logged user "The page is loading"... I made it for partial refresh and it works great but i couldn't make it for full refresh. I have been looking for a solution for this.
I can try jquery, dojo or ajax.
Any suggestion is important.
Regards
C.A.
I've not yet made a dedicated NotesIn9 show for it yet, but I do a demo of a technique in this TLCC webinar.
https://www.youtube.com/watch?v=jBaRSM9Ng_o&index=3&list=PL9nOJ-QrsuFa00dOsdE6EDh_l2fkiYD0D
The relevant part starts around the 26 minute part.
I'm doing this on loading the page initial but I'm sure could be adapted for a full refresh if you were already on the page.
The basic concept is on page load you don't actually load any long running data. You just sent the shell of the page and then in the onClientLoad event you trigger a partial refresh.
<xp:this.resources>
<xp:script src="/xpUtilities.jss" clientSide="false"></xp:script>
<xp:dojoModule name="extlib.dijit.ExtLib"></xp:dojoModule>
<xp:dojoModule name="extlib.dijit.Loading"></xp:dojoModule>
<xp:styleSheet href="/app.css"></xp:styleSheet>
</xp:this.resources>
Page 1
<xp:this.beforePageLoad><![CDATA[#{javascript:viewScope.put("vsHasData", false);}]]></xp:this.beforePageLoad>
  -  Header UI goes here....<xp:br></xp:br>
<xp:br></xp:br>
<xp:br></xp:br>
<xp:panel id="MainContentWrapper">
<xp:panel id="MainContent">
<xp:this.rendered><![CDATA[#{javascript:return viewScope.get("vsHasData");}]]></xp:this.rendered>
<xp:br></xp:br>
<xp:repeat id="repeat1" rows="100" var="rowData"
indexVar="rowIdx">
<xp:this.value><![CDATA[#{javascript:viewScope.get("vsStateMap").keySet()}]]></xp:this.value>
<xp:text escape="true" id="computedField2"
value="#{rowData}">
</xp:text>
-
<xp:text escape="true" id="computedField3">
<xp:this.value><![CDATA[#{javascript:viewScope.get("vsStateMap").get(rowData)}]]></xp:this.value>
<xp:this.converter>
<xp:convertNumber type="number"
integerOnly="true">
</xp:convertNumber>
</xp:this.converter>
</xp:text>
<xp:br></xp:br>
</xp:repeat>
<xp:br></xp:br>
<xp:br></xp:br>
</xp:panel>
</xp:panel>
<xp:eventHandler event="onClientLoad" submit="true" refreshMode="partial" refreshId="MainContentWrapper">
<xp:this.action><![CDATA[#{javascript:return getStateTotals();}]]></xp:this.action>
<xp:this.onStart><![CDATA[XSP.startAjaxLoading("Calculating State Totals. This may take a few moments.")]]></xp:this.onStart>
<xp:this.onComplete><![CDATA[XSP.endAjaxLoading()]]></xp:this.onComplete>
<xp:this.onError><![CDATA[XSP.endAjaxLoading()]]></xp:this.onError>
</xp:eventHandler>
That's a demo page. The stuff to look at is for dojo resources that are added, the fact that I start off hiding the "MainContent" vie a scoped variable and then the end onClientLoad bit.
So the page loads, but the data to generate the repeat control does NOT run because it's in a non rendered panel. So the users get to the page instantly. Then the onClientLoad kicks - on Start it shows a "Please Wait" kind of thing then runs the function to get the data.
When the data is completed, I set a scopedVariable to then show the mainContent area and the endAjaxLoading stuff then triggers and everything gets displayed.
How you do this will not be XPages-specific. It's important to understand the order of events.
User clicks link somewhere to open page
Browser sends request to server
Server receives request and loads component tree for page server-side
Server runs beforePageLoad, afterPageLoad, beforeRenderResponse events
Server generates HTML to send to the browser
Server runs afterRenderResponse event
Server passes resulting HTML to the screen
Browser receives response from server
So adding anything to the XPage that is the target of the browser request at step 2 cannot have an effect. You need to do something client-side at step 1, before the request is sent to the browser. If you think about how you did it for the partial refresh and what's happening, again it's running CSJS before triggering the partial refresh, the same process.
If users are coming externally, the only option is to send them to a redirect web page first, render that, and continue programmatically running step 1.

Replace embedded views with multiple data sources

I am building an application that will have a parent documents with up to 5 different child documents attached to the parent. Each parent can have one and only 1 of each of the 5 types of child documents.
In traditional notes programming I would probably put an embedded view within the parent documents form. I was starting down that path when I wondered if this wouldn't be better done in Xpages with one Xpage that has multiple datasources.
A complicating factor is that each form/data source will have a different group of people who own it - only they can create or edit it. But I don't think this would be a problem.
Couple of ideas to consider ...
don't use response docs ... tie the related docs together via a document key like unid
put the create/edit function for the five child docs in their own separate panels ... childpanel1, childpanel2, etc.
add the datasources for the child docs in the respective panels ... childdoc1, childdoc2, etc
restrict edit access via the acl property for each panel
with multiple data sources on an XPage remember to set ignoreRequestParams="true" for the childdoc data sources
For example, here's the panel structure for the first child doc:
<xp:panel id="childpanel1">
<xp:this.data>
<xp:dominoDocument var="childdoc1" formName="ChildForm1"
ignoreRequestParams="true">
</xp:dominoDocument>
</xp:this.data>
<xp:this.acl>
<xp:acl>
<xp:this.entries>
<xp:aclEntry type="GROUP" name="doc1group" right="EDITOR">
</xp:aclEntry>
</xp:this.entries>
</xp:acl>
</xp:this.acl>
</xp:panel>
More on ignoreRequestParams:
In a two-page application involving a "view" XPage and a "document" XPage, when the application user clicks a link on the view page to open the document on the document page the ID for the document to open is passed with the REQUEST parameters. You can see this in the resulting URL for the document page which will have the ID for the document to open appended to the URL address, for example:
&documentId=49530CA58D17CCE5852575150069D857&action=openDocument
This works perfectly when the document page has only one Domino document data source. However, in the embedded view application the "document" XPage will also include a data source for the xp:viewPanel. When ignoreRequestParams is NOT true for the Domino view data source (and for any other additional data sources on the page, like childdoc1) then the parameters passed in the request ARE evaluated to determine which view entries to display in the xp:viewPasnel. These request parameters point to a UNID that is not the desired data source for the view so no view entries are displayed.
Note, you may not need to set ignoreRequestParams to true for ALL of the data sources on the XPage ... just be aware of this setting and what it does when things get wonky for one of the view or document data sources on the page.
Not sure if your question is how to limit the form creation or how to have something like an embedded view in xPages. Both are easier to do in xPages.
Basically you just need to make the children responses of the parent. I prefer to not use normal response documents and prefer instead to add a field called uid with the unid of the parent to the children. I then filter my datasource to match the uid of the parent document. You can use view controls for this but repeats look even better.
Its a great place to start using dialogs as you can have the second data source in the dialog and the user never needs to leave the page.
As far as restricting the view creation you can do something like hide the button to create a new child based on a criteria.
This action will add the unid of document1 to document3
<xp:modifyField name="uid"
value="#{javascript:document1.getDocument().getUniversalID()}" var="document3">
</xp:modifyField>
Here is the code I use for a repeat control datasource. The view is categorized by uid field
<xp:dominoView var="view7" viewName="VIEWNAME"
keys="#{javascript:document1.getDocument().getUniversalID()}">
</xp:dominoView>
Then the repeat control just grabs the fields you want.
<xp:table styleClass="table">
<xp:tr>
<xp:td>Column Header</xp:td>
<xp:td>Column Header</xp:td>
<xp:td>Column Header</xp:td>
</xp:tr>
<xp:repeat id="repeat3" rows="30" value="#{view7}"
var="rowData">
<xp:tr>
<xp:td>
<xp:text escape="true"
id="computedField3" value="#{rowData.columnname1}">
</xp:text>
</xp:td>
<xp:td>
<xp:text escape="true"
id="computedField4" value="#{rowData.columnname2}">
</xp:text>
</xp:td>
<xp:td>
<xp:text escape="true"
id="computedField5" value="#{rowData.columnname3}">
</xp:text>
</xp:td>
</xp:tr>
</xp:repeat>
</xp:table>
Ignore some of the styleclasses as I am using bootstrap.

XPages SSJS is not started throw Reverse-Proxy

may be someone helps :)
I don't know much about Apache-Reverse-Server
I have a simple X-Page, see the code bellow.
If I open the xpage via
http: //domain1.de/e.nsf/test.xsp
and press the button, in log.nsf i see my print-out "Button is clicked"
If I open the xpage via
https: //example1.someproxy/rp/sproxy/http$domain1.de$80$/e.nsf/test.xsp
and press the button, in log.nsf i DON'T see my print-out "Button is clicked"
The Proxy-Server is installed and configured not by me.
<?xml version="1.0" encoding="UTF-8"?><xp:view xmlns:xp="http://www.ibm.com/xsp/core">
<xp:link escape="true" id="link1" disableTheme="true">
<xp:image id="image1" url="/btn.jpg"></xp:image>
<xp:eventHandler event="onclick" submit="true" refreshMode="complete" >
<xp:this.action><![CDATA[#{javascript:print("Button is clicked");}]]></xp:this.action>
</xp:eventHandler>
</xp:link>
What could be the problem, that the SSJS-code is not started via Reverse-Proxy at all?
Is reverse proxy the problem? Or is the problem that your code is not triggering?
I can't tell from your user id how experienced with XPages you are, but bear in mind a number of steps are performed on the server before it gets to your print statement. One of the key ones is conversion and validation. So if anything on your XPage throws a validation error, it won't run SSJS code.
Do you have a Display Errors control on the XPage and, more importantly, inside the refresh area? If not, add one. We've all spent hours in our early XPages life because validation or data conversion has failed and we didn't add anything to let us know. Once you get more confident, a PhaseListener is another useful tool for checking any or all lifecycle phases are running.

xe:dialog won't open in edit mode with view picklist OpenNTF control

I'm using the Extension Library and XPages to build a web based workflow application. One feature is to prompt a dialog and select the next approver before submitting it forward.
For new documents, the dialog appears, and it also appears when in read mode. It never opens for a saved document. I need it to work in SSJS, though the dialog does open in CSJS. Here is some of the code:
xpMain.xsp contains two custom controls: ccButtons and ccWFloDialogs.
ccButtons "Submit" button:
getComponent('dlgNextOwner').show();
ccWFloDialogs "dlgNextOwner" dialog:
<xe:dialog id="dlgNextOwner" title="Select Supervisor">
<xe:formTable id="ftDlgNextOwner" formTitle="Select Supervisor"
formDescription="You may select a different supervisor."
disableErrorSummary="true">
<xp:this.facets>
<xe:formRow id="formRow1" xp:key="footer" for="txtWFloNextOwner"
labelWidth="125px">
<xp:inputText id="txtWFloNextOwner" style="width:200px"
value="#{viewScope.nextOwner}">
</xp:inputText>
<xe:namePicker id="npNextOwner" dialogTitle="Select Supervisor"
for="txtWFloNextOwner">
<xe:this.dataProvider>
<xe:dominoNABNamePicker addressBookSel="all-public"></xe:dominoNABNamePicker>
</xe:this.dataProvider>
</xe:namePicker>
</xe:formRow>
</xp:this.facets>
</xe:formTable>
</xe:dialog>
In CSJS, I can use the following code and it successfully opens the dialog:
XSP.openDialog("#{id:dlgNextOwner}");
I'm also using Mark Hughes' picklist from the extension library, and if I remove the panel which contains the control and data source, the dialog shows up in SSJS! The code is in a custom control, although, if it's directly in the XPage, the problem is the same. Here is the code for the panel:
<xp:panel
id="vendorDiv">
<xp:this.data>
<xp:dominoView
var="nvVend"
viewName="V_Vend"
ignoreRequestParams="true"
databaseName="other/lookupdb.nsf"
startKeys="#{javascript:viewScope.srchVend}">
</xp:dominoView>
</xp:this.data>
<xe:formTable
id="ftGetVendor"
disableErrorSummary="true"
labelPosition="above">
<xe:formRow
id="frVendor"
for="cfVendorName"
label="Name of the Vendor:">
<xp:text
escape="true"
id="cfVendorName"
value="#{currentDocument.VendorName}"
style="width:200px">
</xp:text>
<xc:viewpicklist
rowsPerPage="15"
buttonImage="./add.png"
tableClass="tablecellgreen"
headerClass="headerclass"
rowClass="odd, even"
searchBar="false"
searchButtonText="Search"
searchButtonClass="button2"
searchBarClass="headerclass"
pagerStyleFirst="navbutton1"
pagerStylePrevious="navbutton2"
pagerStyleCurrent="navbutton4"
pagerStyleNext="navbutton2"
pagerStyleLast="navbutton3"
typeAheadBar="true"
select="Column"
onReturn="Set Scope Value"
bottomBarClass="bottomround headerclass"
cancelButtonText="Cancel"
cancelButtonClass="button2 floatthisright"
type="Single Value"
finishButtonText="Finish"
finishButtonClass="button2 floatthisright"
multiSelectButtonAddImg="./add.png"
multiSelectButtonRemoveImg="./delete.png"
picklistButtonClass="button"
openDialogWith="Link"
picklistLinkImg="./add.png"
multiSelectLinkAddImg="./add.png"
multiSelectLinkRemoveImg="./delete.png"
selectWith="Link"
clearSearchImg="./cross.png"
SelectCellWidth="30px"
dialogID="dlgVend"
dialogTitle="Select a Vendor"
dialogWidth="80%"
refreshID="vendorDiv"
ssjsSelectFunction="getVendorInfo"
varName="viewScope.vendorInfo"
datasrc="nvVend"
selectColumn="4"
linkImg="./add.png"
typeAheadVar="viewScope.srchVend">
<xc:this.viewColumn>
<xp:value>0</xp:value>
<xp:value>1</xp:value>
<xp:value>2</xp:value>
<xp:value>3</xp:value>
</xc:this.viewColumn>
</xc:viewpicklist>
</xe:formRow>
<xe:formRow
id="frVendorStatus"
for="cfVendorStatus"
label="Vendor Registration Status:">
<xp:text
escape="true"
id="cfVendorStatus"
value="#{currentDocument.VendorStatus}">
</xp:text>
</xe:formRow>
<xe:formRow
id="frVendorCountry"
for="cfVendorCountry"
label="Country Name:">
<xp:text
escape="true"
id="cfVendorCountry"
value="#{currentDocument.VendorCountry}">
</xp:text>
</xe:formRow>
</xe:formTable>
</xp:panel>
The requested vendor information populates the fields, without any problem or errors. However, something here seems to prevent dialogs from opening up using SSJS.
Can anyone see anything obvious I'm missing? The data source is in the panel, ignoreRequestParams is true (otherwise it doesn't work).
The main data source is in the entire XPage context. I tried to add the ccWFloDialog custom control outside the main panel, and change the data source to the panel, but that didn't work.
Any ideas?
Forget the dialog for now. This is probably data source related. Suggest you get it working just on the xpage first. With visible fields. then maybe use the rendered property to get it working on the xpage similar to how the dialog would appear. Once you have that working then you should be good to apply to dialog. This idea is to just take the dialog out of the equation first to make sure it works normally.
Instead, I decided to open the dialogs using CSJS, instead of SSJS. I've changed some of logic, and will have a bit more to do to finish this part of the project. Thanks to all!

Extensions Library Dialog Box refresh / caching issue?

I seem to be having an issue with the extensions library dialog box either not refreshing or caching values.
Please see the very simplified example below. Basically the button pops up an extension library dialog box. Contained in the dialog box is a computed field with #Unique() as it's value. On our prod server the number is not being updated when the button is pressed. It works on the first button press but subsequent presses do not update the number.
This occurs only in production and a similar issue has only started occurring in the past couple of weeks. It still works fine on our Dev and QA servers.
My admin contacts are out right now so I don't know the differences in versions between the servers but I will post them when I learn that information.
Here is the code:
<xp:view xmlns:xp="http://www.ibm.com/xsp/core"
xmlns:xc="http://www.ibm.com/xsp/custom"
xmlns:xe="http://www.ibm.com/xsp/coreex">
<xp:this.resources>
<xp:script src="/Validation_SSJS.jss" clientSide="false"></xp:script>
</xp:this.resources>
<xp:br></xp:br>
<xp:br></xp:br>
<xe:dialog id="dlgMsg2" title="Message" style="width:400px;">
<xp:text escape="true" id="computedField1" value="#{javascript:return #Unique();}">
</xp:text>
</xe:dialog><xp:br></xp:br>
<xp:br></xp:br>
<xp:br></xp:br>
<xp:button value="Popup Message" id="button1">
<xp:eventHandler event="onclick" submit="true"
refreshMode="complete">
<xp:this.action><![CDATA[#{javascript:var dlg = getComponent("dlgMsg2");
dlg.show();}]]></xp:this.action>
</xp:eventHandler></xp:button>
</xp:view>
Update: The issue is occurring in both IE and Firefox so it does not appear to be browser related. I am guessing it is not Pistolstar related either as I had a previous issue with PS and Xpages. Pistolstar has discovered that issue and I will update my previous post when I get more details
Update: I checked and our QA and Prod servers are have version 8.5.3.20111208-0717 of the extension library.
I came up with a "workaround" to fix this issue. I added a refresh event handler for the onShow event of the dialog box.
<xe:dialog id="dlgMsg2" title="Message" style="width:400px;">
<xp:text escape="true" id="computedField1" value="#{javascript:return #Unique();}">
</xp:text>
<xp:eventHandler event="onShow" submit="true"
refreshMode="partial" refreshId="computedField1">
</xp:eventHandler></xe:dialog>
It would still be interesting to know the underlying issue.
In the All Properties section of the dialog there is a property called 'RefreshOnShow'.
When set to true the contents of the panel will be refreshed every time the panel goes from a hidden state to a visible state. This should resolve the issue that you are seeing.
It may be unlikely, but page persistence options in the xsp.properties could alter the way the page behaves across environments. There is the xsp.properties on the database and on the server. XPages Portable Command Guide has more details on the different settings, but settings could change what gets retained between requests.

Resources