Reputation: 57
I have two buttons in different custom controls which within their onclick events call context.redirectToPage(). In one instance, this causes an HTTP redirect (HTTP status of 302) to the expected URL (i.e. header Location = http://frontend.company.com/path/to/file.nsf/myXpages.xsp?documentId=C699C5D6E81721EA85257A2F00683319&openDocument). In the other instance, it returns a tag like this:
<script>window.location.href='http://backend.company.com:81/path/to/file.nsf/myXpage.xsp?documentId=C699C5D6E81721EA85257A2F00683319&openDocument'</script>
Both instances have submit=true, refresh=complete and immediate=true. Both have client-side scripts which execute correctly and a few lines of SSJS that execute before the redirect call. The only difference that I can conceive that might be causing this is that the button which returns the script is within an (xe:dialog).
The astute among you will notice why this is a problem for me as our Domino server is behind a reverse proxy. Mere mortals do not have direct access to Domino and so the URL generated in the script tag will not work.
Does anyone have an idea on how to get the preferred behavior of a 302 redirect from the second button, or even a way to get it to use the correct URL? Or even shed some light on why the behavior would be different?
Thanks,
Rich
EDIT: code for button that generates script tag for context.redirect():
<xp:button
id="errorReloadButton"
value="Reload Page">
<xp:this.rendered><![CDATA[#{javascript:whichButton == "reload"}]]></xp:this.rendered>
<xp:eventHandler
event="onclick"
submit="true"
refreshMode="complete"
immediate="true">
<xp:this.action>
<xp:actionGroup>
<xp:executeScript>
<xp:this.script><! [CDATA[#{javascript:sessionScope.remove("errors");
var c = getComponent("errorDialog")
c.hide();
var redirectTarget = view.getPageName() + '?documentId=' + compositeData.docID + '&openDocument';
context.redirectToPage(redirectTarget,true);
}]]></xp:this.script>
</xp:executeScript>
</xp:actionGroup>
</xp:this.action>
<xp:this.script>
<xp:executeClientScript>
<xp:this.script><![CDATA[setClean("#{javascript:compositeData.docID}");
XSP._setDirty(false,"");]]></xp:this.script>
</xp:executeClientScript>
</xp:this.script>
</xp:eventHandler>
</xp:button>
EDIT 2: source for button that correctly forces a 302 redirect:
<xp:button
id="cancelButton"
value="Cancel"
rendered="#{javascript:compositeData.documentDataSource.isEditable()}">
<xp:eventHandler
event="onclick"
submit="true"
refreshMode="complete"
onError="handleError(arguments[0],arguments[1])"
immediate="true">
<xp:this.action>
<xp:actionGroup>
<xp:executeScript>
<xp:this.script><![CDATA[#{javascript:var xdoc:NotesXspDocument = compositeData.documentDataSource;
if(xdoc.isNewNote()){
return;
}
var doc:NotesDocument = xdoc.getDocument(false);
/* more code here, not relevant to this */
var docid = doc.getUniversalID();
context.redirectToPage(view.getPageName() + '?documentId=' + docid + '&openDocument')}]]></xp:this.script>
</xp:executeScript>
</xp:actionGroup>
</xp:this.action>
<xp:this.script>
<xp:executeClientScript>
<xp:this.script><![CDATA[setClean("#{javascript:docId(compositeData.documentDataSource)}");
if(#{javascript:compositeData.documentDataSource.isNewNote()}){
popPageStack();
return false;
}]]></xp:this.script>
</xp:executeClientScript>
</xp:this.script>
</xp:eventHandler>
</xp:button>
Upvotes: 0
Views: 1969
Reputation: 10485
There are two ways for fixing your problems: You could hard code the redirection to the new URL, f.e.
facesContext.getExternalContext().redirect( "http://stackoverflow.com" );
Or you have to modify the the HTTP response with your reverse proxy.
The last option is the better one, because this would affect all partial refreshs too. There is a additional HTTP header X-XspLocation which contains the target URL which has to be modified.
EDIT:
the script is within an (xe:dialog). -> That's the reason. My fault, I have not read this information. Events inside a xe:dialog will be forced to partial refreshs, otherwise they would not work "inside the dialog". This affects all redirects, they will always return a Javascript and a X-XspLocation header with the target.
In most cases the returned Javascript will not be executed, because of the header in the response, wich is parsed earlier (and forces a redirection).
As I written above, the best approach is to change the reverse proxy configuration. Alternativly you could change the server to use the external name. Or return the external address in the button code.
Upvotes: 1