Aug 27, 2011 5:43 PM
170 Posts

redirecting to another xpage but reqestscope is empty

  • Category: Server Side JavaScript
  • Platform: All
  • Release: 8.5.2
  • Role: Developer
  • Tags: requestScope
  • Replies: 8
 If I use the following code behind a button on XPages 1
 

requestScope.MyVar="Hello"
context.redirectToPage("test2")
 
If I have a computed field on XPage 2 called test2 that picks up the MyVar from the requestScope  
the variable is empty.
 
What am I missing here ? 
Should it not be possible to use a requestScope variable to store information when navigating to another xpage ? 
Aug 27, 2011 10:28 PM
272 Posts
Re: redirecting to another xpage but reqestscope is empty
Hi,
 
the requestScope is valid only in the current HTTP request. If you redirect to another page, the request is finished, because the client receives a response ( a redirect based on HTTP or javascript ). Then, the client creates a new request to the redirected page, and the data in requestScope is lost.
 
You have to use the sessionScope for this.
 
Sven
Aug 28, 2011 2:54 AM
170 Posts
Re: redirecting to another xpage but reqestscope is empty
 The problem with this is that if the end users opens up several pages then they will get the same session and the same sessionscope.
 And then you will get problems, any ideas on how to resolve that kind of problem If you want to pass information between pages?
Aug 28, 2011 3:14 AM
272 Posts
Re: redirecting to another xpage but reqestscope is empty
If you have just a few informations, you could try to use URL parameters between the redirects. Another idea is to use several variables in the session scope, something like this:

requestScope.MyVarTest2="Hello"
context.redirectToPage("test2")
 
 
Sven
Dec 30, 2011 6:00 AM
57 Posts
Re: redirecting to another xpage but reqestscope is empty
solution is to make our own flash scope bean
 
http://www.bleedyellow.com/blogs/andyc/entry/a_flash_scope_for_xpages?lang=en_gb
Dec 30, 2011 9:25 AM
57 Posts
Re: redirecting to another xpage but reqestscope is empty
FacesContext.getCurrentInstance().getExternalContext().dispatch(arg0)
can not be used in Xpages "Function is not available in the Domino environement " and they spell wrong on this excpetion........."environement",    "environment"
 
but we can do this
pageA.xsp and pageB.xsp
pageA.xsp defines requestScope param, and pageB.xsp catch it
 
put a button in pageA.xsp
 
<xp:button value="Label" id="button1">
        <xp:eventHandler event="onclick" submit="true"
            refreshMode="complete">
            <xp:this.action><![CDATA[#{javascript:requestScope.paramA="I am requestScope param";
var viewRoot1:UIViewRoot =facesContext.getApplication().getViewHandler().createView(facesContext, "/pageB.xsp");
facesContext.setViewRoot(viewRoot1);
facesContext.renderResponse();
}]]></xp:this.action>
        </xp:eventHandler>
    </xp:button>
Dec 30, 2011 11:38 AM
272 Posts
Re: redirecting to another xpage but reqestscope is empty
Hi,
 
adding xsp.redirect=false to the xsp.properties-file would give you the same result and it is much easier to implement ;-)
I have written an article about this feature here (on german only).
 
Sven
 
http://blog.hasselba.ch
Dec 30, 2011 7:08 PM
57 Posts
Re: redirecting to another xpage but reqestscope is empty
thanks, Sven, where did you find the list of configurable properties in xsp.property? 
 
but there is a method for that now, no need to configure in xsp.property 
requestScope.paramA="something";
context.redirectToPage("/pageB.xsp",false);

 
I do believe that the code behind redirect=false, is the more or less the same as manually choosing a page viewroot for rendering
trace of code:
com.ibm.xsp.designer.context.XSPContext.redirectToPage(String paramString, boolean paramBoolean)
com.ibm.xsp.designer.context.XSPContext.renderPage(String paramString, boolean paramBoolean)
com.ibm.xsp.application.NavigationHandlerImpl.createView(localFacesContext, paramString, paramBoolean)
com.ibm.xsp.controller.FacesControllerImpl.restoreView(FacesContext paramFacesContext, String paramString)
 
REF: https://forums.oracle.com/forums/thread.jspa?threadID=654384
 
 

Dec 31, 2011 12:13 PM
272 Posts
Re: redirecting to another xpage but reqestscope is empty
You can find a description of the properties in the xsp.properties.sample-file. As far as I know, the "XPages Portable Command Guide" (available Feb. 2012) will have a complete(?) list of all properties.
The redirection-parameter will affect ALL redirections (f.e. links etc.), not only the redirects you are do with context.redirectToPage(). If set to false, the request scope will work "as designed".
 
Sven