Skip to content

Commit 920b8d6

Browse files
authored
Merge pull request #4998 from eclipse-ee4j/mojarra-issue-4977_improved-fix
Flash doPostPhaseActions() should be done before endDocument()
2 parents 2ca24e0 + 8b92fe2 commit 920b8d6

3 files changed

Lines changed: 15 additions & 20 deletions

File tree

impl/src/main/java/com/sun/faces/application/view/FaceletViewHandlingStrategy.java

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@
128128
import com.sun.faces.application.ApplicationAssociate;
129129
import com.sun.faces.config.WebConfiguration;
130130
import com.sun.faces.context.StateContext;
131-
import com.sun.faces.context.flash.ELFlash;
132131
import com.sun.faces.facelets.el.ContextualCompositeMethodExpression;
133132
import com.sun.faces.facelets.el.VariableMapperWrapper;
134133
import com.sun.faces.facelets.impl.DefaultFaceletFactory;
@@ -438,20 +437,9 @@ public void renderView(FacesContext ctx, UIViewRoot viewToRender) throws IOExcep
438437
ResponseWriter writer = origWriter.cloneWithWriter(stateWriter);
439438
ctx.setResponseWriter(writer);
440439

441-
// Don't call startDoc and endDoc on a partial response
442440
if (ctx.getPartialViewContext().isPartialRequest()) {
443-
Map<Object, Object> contextMap = ctx.getAttributes();
444-
contextMap.put(ELFlash.DELAYED_END_DOCUMENT, true);
441+
// Any pre/post processing logic such as startDocument(), doPostPhaseActions() and endDocument() must be done in PartialViewContextImpl, see also #4977
445442
viewToRender.encodeAll(ctx);
446-
contextMap.remove(ELFlash.DELAYED_END_DOCUMENT);
447-
try {
448-
ctx.getExternalContext().getFlash().doPostPhaseActions(ctx);
449-
} catch (UnsupportedOperationException uoe) {
450-
if (LOGGER.isLoggable(FINE)) {
451-
LOGGER.fine("ExternalContext.getFlash() throw UnsupportedOperationException -> Flash unavailable");
452-
}
453-
}
454-
ctx.getPartialViewContext().getPartialResponseWriter().endDocument();
455443
} else {
456444
if (ctx.isProjectStage(Development)) {
457445
FormOmittedChecker.check(ctx);

impl/src/main/java/com/sun/faces/context/PartialViewContextImpl.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import static com.sun.faces.renderkit.RenderKitUtils.PredefinedPostbackParameter.PARTIAL_EXECUTE_PARAM;
2020
import static com.sun.faces.renderkit.RenderKitUtils.PredefinedPostbackParameter.PARTIAL_RENDER_PARAM;
2121
import static com.sun.faces.renderkit.RenderKitUtils.PredefinedPostbackParameter.PARTIAL_RESET_VALUES_PARAM;
22+
import static java.util.logging.Level.FINE;
2223
import static javax.faces.FactoryFinder.VISIT_CONTEXT_FACTORY;
2324

2425
import java.io.IOException;
@@ -56,7 +57,6 @@
5657

5758
import com.sun.faces.RIConstants;
5859
import com.sun.faces.component.visit.PartialVisitContext;
59-
import com.sun.faces.context.flash.ELFlash;
6060
import com.sun.faces.renderkit.RenderKitUtils.PredefinedPostbackParameter;
6161
import com.sun.faces.util.FacesLogger;
6262
import com.sun.faces.util.HtmlUtils;
@@ -308,6 +308,7 @@ public void processPartial(PhaseId phaseId) {
308308
if (isRenderAll()) {
309309
renderAll(ctx, viewRoot);
310310
renderState(ctx);
311+
doFlashPostPhaseActions(ctx);
311312
writer.endDocument();
312313
return;
313314
}
@@ -322,10 +323,9 @@ public void processPartial(PhaseId phaseId) {
322323

323324
renderState(ctx);
324325
renderEvalScripts(ctx);
326+
doFlashPostPhaseActions(ctx);
325327

326-
if (!ctx.getAttributes().containsKey(ELFlash.DELAYED_END_DOCUMENT) || !(Boolean) ctx.getAttributes().get(ELFlash.DELAYED_END_DOCUMENT)) {
327-
writer.endDocument();
328-
}
328+
writer.endDocument();
329329
} catch (IOException ex) {
330330
this.cleanupAfterView();
331331
} catch (RuntimeException ex) {
@@ -335,6 +335,16 @@ public void processPartial(PhaseId phaseId) {
335335
}
336336
}
337337
}
338+
339+
private void doFlashPostPhaseActions(FacesContext ctx) {
340+
try {
341+
ctx.getExternalContext().getFlash().doPostPhaseActions(ctx);
342+
} catch (UnsupportedOperationException uoe) {
343+
if (LOGGER.isLoggable(FINE)) {
344+
LOGGER.fine("ExternalContext.getFlash() throw UnsupportedOperationException -> Flash unavailable");
345+
}
346+
}
347+
}
338348

339349
/**
340350
* @see javax.faces.context.PartialViewContext#getPartialResponseWriter()

impl/src/main/java/com/sun/faces/context/flash/ELFlash.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -661,9 +661,6 @@ public void doPostPhaseActions(FacesContext context) {
661661
public static final String ACT_AS_DO_LAST_PHASE_ACTIONS =
662662
ELFlash.class.getPackage().getName() + ".ACT_AS_DO_LAST_PHASE_ACTIONS";
663663

664-
public static final String DELAYED_END_DOCUMENT =
665-
ELFlash.class.getPackage().getName() + ".DELAYED_END_DOCUMENT";
666-
667664
/**
668665
* <p>This is the most magic of methods. There are several scenarios
669666
* in which this method can be called, but the first time it is

0 commit comments

Comments
 (0)