您的位置:首页 > Web前端 > JavaScript

xpages调用后台代理

2015-09-29 14:57 561 查看
前段时间做了一个类似门户添加系统的功能,大体框架是,后台有几十个文档(主文档),文档里有读者域(都包括管理员),还有与主文档对应的目录文档(只有名字和临时记录用户),用户在xpages页面上看不到任何文档,然后用户点击添加,可以随意添加系统(在文档的读者域中添加上用户的邮箱)。

因为用户没有操作文档的权限(因读者域中并没有用户),所以需要按钮执行后台的代理(本文使用LS代理,使用java代理也是一样的),具体操作如下。

1、在前台按钮的服务前端添加如下JavaScript代码:

//comboBox1是获得用户的选择

var comboBox1:com.ibm.xsp.component.xp.XspSelectOneMenu = getComponent("域名字");

var a = comboBox1.getValue();

//根据用户的选择找到对应目录文档,在目录文档中的临时用户域中添加上当前用户

var view = database.getView("视图名字")

var doc:NotesDocument = view.getDocumentByKey(a);

if(doc!=null){

doc.computeWithForm(false,false);

doc.save();

//执行代理,将目录文档ID传到代理中
agent = database.getAgent("代理名字");

unid = doc.getNoteID();

agent.run(unid);

return;

}

2、然后在代理中创建一个LS代理,注意:代理的触发器必须是基于事件,操作菜单选择,目标是无。

 Sub Initialize

Dim ss As New NotesSession
Dim db As NotesDatabase
Dim view As NotesView
Dim doc As NotesDocument
Dim sdoc As NotesDocument
Dim ag As NotesAgent
Dim noteid As string

Set db = ss.Currentdatabase
Set ag = ss.Currentagent
noteid = ag.Parameterdocid

Set doc = db.Getdocumentbyid(noteid)
If doc Is Nothing Then
Print"啊啊啊,没有找到目录文档啊"
Exit sub
End If
Dim notename As String
notename = doc.dbname(0)
Set view = db.Getview("ALL")
Set sdoc = view.Getdocumentbykey(notename)
If sdoc Is Nothing Then
Print"啊啊啊,没有找到配置文档啊"
Exit Sub
End If
Dim item As NotesItem
Set item = sdoc.GetFirstItem("docReader")
Dim temname As String
temname = doc.temname(0)
Call item.AppendToTextList(temname)
item.IsReaders=True
Call sdoc.Save( False, True )

End Sub

以上的代码仅仅是找到主文档,然后得到目录文档中的用户名添加到主文档的读者域中,这样就可以实现任何的用户添加都是执行的管理员的权限。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息