Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/omnifaces/omnifaces into…
Browse files Browse the repository at this point in the history
… develop
  • Loading branch information
BalusC committed Dec 11, 2016
2 parents 931a4e2 + 23d7baf commit 4d80a56
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import javax.faces.event.AbortProcessingException;
import javax.faces.event.ExceptionQueuedEvent;
import javax.faces.event.PhaseId;
import javax.faces.lifecycle.Lifecycle;
import javax.faces.webapp.FacesServlet;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
Expand Down Expand Up @@ -533,7 +534,9 @@ private void renderErrorPageView(FacesContext context, final HttpServletRequest

try {
context.setCurrentPhaseId(PhaseId.RENDER_RESPONSE);
getLifecycle(context).render(context);
Lifecycle lifecycle = getLifecycle(context);
lifecycle.execute(context);
lifecycle.render(context);
context.responseComplete();
}
catch (Exception e) {
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/org/omnifaces/util/Faces.java
Original file line number Diff line number Diff line change
Expand Up @@ -1016,14 +1016,17 @@ public static boolean isAjaxRequestWithPartialRendering() {
}

/**
* Returns whether the current request is a postback.
* Returns whether the current request is a postback. This not only delegates to {@link FacesContext#isPostback()}
* which checks the presence of <code>javax.faces.ViewState</code> request parameter, but this also explicitly
* checks the HTTP request method. So this should exclude GET requests having a <code>javax.faces.ViewState</code>
* request parameter in query string.
* <p>
* This is also available in EL as <code>#{faces.postback}</code>.
* @return <code>true</code> for a postback, <code>false</code> for a non-postback (GET) request.
* @see FacesContext#isPostback()
*/
public static boolean isPostback() {
return getContext().isPostback();
return FacesLocal.isPostback(getContext());
}

/**
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/org/omnifaces/util/FacesLocal.java
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,14 @@ public static boolean isAjaxRequestWithPartialRendering(FacesContext context) {
return pvc.isAjaxRequest() && !pvc.isRenderAll();
}

/**
* {@inheritDoc}
* @see Faces#isPostback()
*/
public static boolean isPostback(FacesContext context) {
return "POST".equalsIgnoreCase(getRequest(context).getMethod()) && context.isPostback();
}

/**
* {@inheritDoc}
* @see Faces#getRequestParameterMap()
Expand Down
11 changes: 10 additions & 1 deletion src/main/java/org/omnifaces/viewhandler/OmniViewHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@
import static org.omnifaces.util.Components.buildView;
import static org.omnifaces.util.Faces.responseComplete;
import static org.omnifaces.util.FacesLocal.getRenderKit;
import static org.omnifaces.util.FacesLocal.getRequestQueryString;
import static org.omnifaces.util.FacesLocal.getRequestURI;
import static org.omnifaces.util.FacesLocal.isDevelopment;
import static org.omnifaces.util.FacesLocal.redirectPermanent;
import static org.omnifaces.util.Utils.isEmpty;

import java.io.IOException;
import java.util.Map;
Expand Down Expand Up @@ -116,7 +120,9 @@ public void renderView(FacesContext context, UIViewRoot viewToRender) throws IOE
}

/**
* Create a dummy view, restore only the view root state and then immediately explicitly destroy the view.
* Create a dummy view, restore only the view root state and then immediately explicitly destroy the view. Or, if
* there is no view root state and the current request is triggered by a beacon, then explicitly send a permanent
* redirect to base URI in order to strip off all unload related query parameters.
*/
private UIViewRoot unloadView(FacesContext context, String viewId) {
UIViewRoot createdView = createView(context, viewId);
Expand All @@ -127,6 +133,9 @@ private UIViewRoot unloadView(FacesContext context, String viewId) {
context.getApplication().publishEvent(context, PreDestroyViewMapEvent.class, UIViewRoot.class, createdView);
Hacks.removeViewState(context, manager, viewId);
}
else if (!isEmpty(getRequestQueryString(context))) {
redirectPermanent(context, getRequestURI(context));
}

responseComplete();
return createdView;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,16 @@ OmniFaces.Unload = (function(Util, navigator, window, document) {
}

try {
var url = form.action.split(/[?#;]/)[0] + "?omnifaces.event=unload&id=" + id + "&" + VIEW_STATE_PARAM + "=" + encodeURIComponent(form[VIEW_STATE_PARAM].value);
var url = form.action.split(/[?#;]/)[0];
var query = "omnifaces.event=unload&id=" + id + "&" + VIEW_STATE_PARAM + "=" + encodeURIComponent(form[VIEW_STATE_PARAM].value);

if (navigator.sendBeacon) {
navigator.sendBeacon(url); // Synchronous XHR is deprecated during unload event, modern browsers offer Beacon API for this which will basically fire-and-forget the request.
navigator.sendBeacon(url + "?" + query); // Synchronous XHR is deprecated during unload event, modern browsers offer Beacon API for this which will basically fire-and-forget the request.
}
else {
var xhr = new XMLHttpRequest();
xhr.open("POST", url, false);
xhr.send(null);
xhr.send(query);
}
}
catch (e) {
Expand Down

0 comments on commit 4d80a56

Please sign in to comment.