mojarra icon indicating copy to clipboard operation
mojarra copied to clipboard

Ajax redirect fails silently when extension is used

Open javaserverfaces opened this issue 9 years ago • 11 comments
trafficstars

Ajax redirects fail silently when the element is used in the partial response:

<?xml version='1.0' encoding='UTF-8'?>
<partial-response id="j_id1">
<changes>
<extension parameterNamespace="j_id1"></extension>
</changes>
<redirect url="/ajax-redirect-fails-silently-when-extension-is-used-reproducer-1.0-SNAPSHOT/faces/page2.xhtml"></redirect>
</partial-response>

If the extension element is removed, redirects work correctly:

<?xml version='1.0' encoding='UTF-8'?>
<partial-response id="j_id1">
<redirect url="/ajax-redirect-fails-silently-when-extension-is-used-reproducer-1.0-SNAPSHOT/faces/page2.xhtml"></redirect>
</partial-response>

Steps to reproduce:

1. Clone the reproducer project:

git clone https://github.com/stiemannkj1/ajax-redirect-fails-silently-when-extension-is-used-reproducer &&
    cd ajax-redirect-fails-silently-when-extension-is-used-reproducer

2. Build the project with maven:

mvn clean install

3. Deploy the project to tomcat:

cp target/ajax-redirect-fails-silently-when-extension-is-used-reproducer*.war $TOMCAT_HOME/webapps/

4. Navigate to index.xhtml (http://localhost:8080/ajax-redirect-fails-silently-when-extension-is-used-reproducer-1.0-SNAPSHOT/faces/index.xhtml).

5. Click on the page2 button.

If the bug still exists, an ajax POST will occur with a redirect, but the browser will stay on index.html instead of navigating to page2.xhtml.

Affected Versions

[2.1.29-06, 2.2.13]

javaserverfaces avatar Sep 20 '16 13:09 javaserverfaces

Reported by stiemannkj1

javaserverfaces avatar Sep 20 '16 13:09 javaserverfaces

stiemannkj1 said: I've sent a pull request to fix this issue to vsingleton here: https://github.com/vsingleton/mojarra/pull/9

The fix should be forward ported and back ported.

javaserverfaces avatar Sep 20 '16 14:09 javaserverfaces

zhangxinyuan said: I can't find your pull request from https://github.com/vsingleton/mojarra/pull/9 now.

javaserverfaces avatar Dec 19 '16 02:12 javaserverfaces

stiemannkj1 said: Sorry, the link was broken due to a repo name change: https://github.com/vsingleton/mojarra_read-only_mirror/pull/9

javaserverfaces avatar Dec 19 '16 02:12 javaserverfaces

stiemannkj1 said: vsingleton,

Here is the change:

var partialResponse = xml.getElementsByTagName("partial-response")[0];
 var partialResponseId = partialResponse.getAttribute("id");
 var responseType = partialResponse.firstChild;

 for (var i = 0; i < partialResponse.childNodes.length; i++) {
     if (partialResponse.childNodes[i].nodeName === "error") {
         responseType = partialResponse.childNodes[i];
         break;
     }
+
+    if (partialResponse.childNodes[i].nodeName === "redirect") {
+        responseType = partialResponse.childNodes[i];
+    }
 }

 if (responseType.nodeName === "error") { // it's an error

However, this change may violate the spec. The "Receiving The Ajax Response" section of the JSF Specification (section 13.3.4) states that:

The elements in the response must be processed in the order they appear in the response.

But, lines 2817-2822 of jsf.js seem to process elements before any other elements. If the way errors are being handled is not a violation of the Spec, then would processing elements before others be a spec violation?

Manfred Riem, Ed Burns, what do you think?

  • Kyle

javaserverfaces avatar Feb 01 '17 15:02 javaserverfaces

Was assigned to ZhangXinyuan

javaserverfaces avatar Sep 20 '16 13:09 javaserverfaces

This issue was imported from java.net JIRA JAVASERVERFACES-4187

javaserverfaces avatar May 02 '17 11:05 javaserverfaces

Hi @stiemannkj1 ,could you please create a new pull request for this issue.

xinyuan-zhang avatar Jul 04 '17 08:07 xinyuan-zhang

@xinyuan-zhang, PR here: https://github.com/javaserverfaces/mojarra/pull/4258

Note that I'm still not sure if this violates the spec:

@vsingleton, @manfredriem, @edburns, The "Receiving The Ajax Response" section of the JSF Specification (section 13.3.4) states that:

The elements in the response must be processed in the order they appear in the response.

However, lines 2817-2822 of jsf.js seem to process <error> elements before any other elements. If this is not a violation of the Spec, then <redirect> elements should recieve similar treatment, and this fix is valid. What do you think?

stiemannkj1 avatar Jul 04 '17 14:07 stiemannkj1

Please see this important message regarding community contributions to Mojarra.

https://javaee.groups.io/g/jsf-spec/message/30

Also, please consider joining that group, as that group has taken the place of the old [email protected] mailing list.

Thanks,

Ed Burns

edburns avatar Oct 29 '17 03:10 edburns

@edburns, @xinyuan-zhang, I've signed the OCA, so my code should be able to be merged. But I'd appreciate any insight either of you have into whether the change violates the JSF Spec or not.

stiemannkj1 avatar Mar 22 '18 17:03 stiemannkj1