How can you use SessionAsSigner in a Java Bean called from an XPage?

风格不统一 提交于 2019-12-11 03:33:10

问题


According to Phillip Riand (see: discussion on openNTF) this is not possible... They need to know the design element to find out who signed it. Therefore, it is only available in SSJS.


回答1:


There are 2 ways that I know of to use the sessionAsSigner object in Java beans:

1 By resolving the sessionAsSigner object:

FacesContext context = FacesContext.getCurrentInstance();
Session sessionAsSigner = context.getApplication().getVariableResolver().
        resolveVariable(context, "sessionAsSigner");

2 By using the getCurrentSessionAsSigner() function from the com.ibm.xsp.extlib.util.ExtLibUtil class in the Extension Library.

To be able to use it (in Java as wel as SSJS) you'll want to make sure that all design elements were signed by the same user ID. If that's not the case, the sessionAsSigner object will not be available ('undefined').




回答2:


I found that the solution is right at hand :-)

I changed my XPage (in this example an XAgent) to:

<xp:view xmlns:xp="http://www.ibm.com/xsp/core" rendered="false">

This is an xAgent returning json data...

<xp:this.afterRenderResponse><![CDATA[#{javascript:Controller.verify(sessionAsSigner)}]]></xp:this.afterRenderResponse>

and in the bean I simply used the session in the argument when I needed to open a database/document as signer. Sometimes the solution is so simple :-)

/John




回答3:


This is quite an old post that I just stumbled upon. Tried some of the solutions mentioned above:

  1. resolveVariable did not work for me, at least not for sessionAsSigner as this throws a runtime error (I can resolve plain old session, though...)

  2. to be honest I didn't quite understand the Controller.verify(sessionAsSigner) method; is Controller something specific to XAgents? If so, I don't have an XAgent here, so can't use it

  3. didn't feel like importing extra ExtLib classes here...

So I came up with another solution that appears to be very simple:

created a method in my javaBean that takes a session object as argument; since sessionAsSigner belongs to the same class as session I don't have to import something new.

Javacode is:

public void testSession(Session s) throws Exception{
        System.out.println(" > test effective user for this session = " 
             + s.getEffectiveUserName());
}

This is called from SSJS as either

mybean.testSession(session);

or

myBean.testSession(sessionAsSigner);

Maybe helps others, too



来源:https://stackoverflow.com/questions/11401862/how-can-you-use-sessionassigner-in-a-java-bean-called-from-an-xpage

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!