问题
In a xpage, it requires user to login. After the user login, there is a view shows the information that belongs to the logged in user.
Please find the xpage code below for your review: (please note, the view in Lotus Client contains various columns e.g. UserName, UserID, etc., but in xpage, due to the user needs to login, so I do not display the user name in the xpage)
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">
<xp:viewPanel rows="30" id="viewPanel1" pageName="/BookVenue.xsp" viewStyle="width:700.0px">
<xp:this.data>
<xp:dominoView var="view4" viewName="UserBookedVenueInfo">
</xp:dominoView>
</xp:this.data>
<xp:viewColumn columnName="Venue" id="viewColumn1" displayAs="link">
<xp:viewColumnHeader value="Venue" id="viewColumnHeader1" sortable="true">
</xp:viewColumnHeader>
</xp:viewColumn>
<xp:viewColumn columnName="ReturnDate" id="viewColumn2" displayAs="link">
<xp:viewColumnHeader value="Return Date" id="viewColumnHeader2" sortable="true">
</xp:viewColumnHeader>
</xp:viewColumn>
<xp:viewColumn columnName="Remarks" id="viewColumn3" displayAs="link">
<xp:viewColumnHeader value="Remark" id="viewColumnHeader3" sortable="true">
</xp:viewColumnHeader>
</xp:viewColumn>
<xp:this.facets>
<xp:pager partialRefresh="true" layout="Previous Group Next" xp:key="footerPager" id="pager1">
</xp:pager>
</xp:this.facets>
</xp:viewPanel>
</xp:view>
About the view, I use formula to get the data
tmp:=@Name([CN];@UserName);
SELECT Form = "BookVenue" & UserName =tmp
When I preview the xpage in the browser (Internet Explorer), the view can display the relevant data. However, when I close the browser, I use another account to login, the view shows the previous user's information.
Please consider the following scenario, at the first time, I use tester A account to login, the view can show information related to tester A. Then I close the browser, and reopen the xpage, it requires me to login so I use tester B account to login, the view shows the information related to tester A. I close the browser and use tester C account to login, the view still shows the information related to tester A.
Suppose I use tester C account to login and the view still shows the information related to tester A. I do not close the browser. In the view, I change the formula to this:
SELECT Form = "BookVenue" & UserName = @Name([CN];@UserName)
I refresh the browser, the view shows the data related to tester C. Then I close the browser and use tester B account to login. The view displays the data related to tester C.
The strange thing is, when I change the formula and refresh the browser, the view shows the proper data related to the logged in user.
tmp:=@Name([CN];@UserName);
SELECT Form = "BookVenue" & UserName =tmp
Why the view "remember" the previous logged in user's information? I always think if the user login to the xpage, then when the user close the browser, the connection between the user and the xpage is closed. (maybe my concept is not correct)
If I keep change the formula in the view respectively, the view can show the proper data related to the user.(I have no idea why this approach works.)
My question is how to refresh the view when different user login? I guess the problem is in the formula:
tmp:=@Name([CN];@UserName);
SELECT Form = "BookVenue" & UserName =tmp
and
SELECT Form = "BookVenue" & UserName = @Name([CN];@UserName)
However I search on the internet @Name([CN];@UserName) is correct to get the username. I also recreate the view and the xpage again but the result is the same. I still need to the change the formula in the view to refresh the view in xpage.
Would someone let me know my mistake please? Thank you.
Reference:
http://www.ibm.com/support/knowledgecenter/SSVRGU_9.0.0/com.ibm.designer.domino.main.doc/H_USERNAME.html
回答1:
You cannot use @Username in view selections (see comment above). Nevertheless you can achieve this by the following solution design: - Create a view with a categorized column which displays the Username - in The View Panel, add a "Filter by category name " calculated using session.getEffectiveUserName()
The XPage below uses a view named "view" with a "cat" field which contains the username to filter.
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">
<xp:this.data>
<xp:dominoView var="view1" viewName="view"
categoryFilter="#{javascript:session.getEffectiveUserName()}">
</xp:dominoView>
</xp:this.data>
<xp:viewPanel value="#{view1}" id="viewPanel1">
<xp:this.facets>
<xp:pager partialRefresh="true" layout="Previous Group Next"
xp:key="headerPager" id="pager1">
</xp:pager>
</xp:this.facets>
<xp:viewColumn columnName="cat" id="viewColumn1">
<xp:this.facets>
<xp:viewColumnHeader value="Cat" xp:key="header"
id="viewColumnHeader1">
</xp:viewColumnHeader>
</xp:this.facets>
</xp:viewColumn>
<xp:viewColumn columnName="subject" id="viewColumn2">
<xp:this.facets>
<xp:viewColumnHeader value="Subject" xp:key="header"
id="viewColumnHeader2">
</xp:viewColumnHeader>
</xp:this.facets>
</xp:viewColumn>
</xp:viewPanel></xp:view>
Please be aware that using this solution all users still can access and read all documents (in theory). If you want to make the documents unavailable, you should implement reader fields. More information can be found here http://www.ibm.com/developerworks/lotus/library/reader-names/
来源:https://stackoverflow.com/questions/39160841/xpages-refresh-the-view-when-different-user-login