Skip to content

Commit 59ca7b0

Browse files
committed
Improved #5543; save encoding in session AFTER rendering view as it will
otherwise fail on 1st request when session hasn't been created yet
1 parent ac0a34e commit 59ca7b0

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,11 @@ public void renderView(FacesContext ctx, UIViewRoot viewToRender) throws IOExcep
454454
writer.endDocument();
455455
}
456456

457+
// Save encoding in Session for consult in subsequent postback request as per spec section "2.5.2.2. Determining the Character Encoding".
458+
if (ctx.getExternalContext().getSession(false) != null) {
459+
ctx.getExternalContext().getSessionMap().put(CHARACTER_ENCODING_KEY, writer.getCharacterEncoding());
460+
}
461+
457462
// Finish writing
458463
writer.close();
459464

@@ -929,11 +934,6 @@ protected ResponseWriter createResponseWriter(FacesContext context) throws IOExc
929934
// Save encoding in UIViewRoot for faster consult when Util#getResponseEncoding() is invoked again elsewhere.
930935
context.getViewRoot().getAttributes().put(FACELETS_ENCODING_KEY, encoding);
931936

932-
// Save encoding in Session for consult in subsequent postback request as per spec section "2.5.2.2. Determining the Character Encoding".
933-
if (context.getExternalContext().getSession(false) != null) {
934-
context.getExternalContext().getSessionMap().put(CHARACTER_ENCODING_KEY, encoding);
935-
}
936-
937937
// Now, clone with the real writer
938938
ResponseWriter writer = initWriter.cloneWithWriter(extContext.getResponseOutputWriter());
939939

impl/src/main/java/com/sun/faces/util/Util.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1667,7 +1667,7 @@ public static String getResponseEncoding(FacesContext context, String defaultEnc
16671667

16681668
if (encoding == null && context.getExternalContext().getSession(false) != null) {
16691669
// 4. If still none found then get previously known request or response encoding from session.
1670-
// See also ViewHandler#initView() and FaceletViewHandlingStrategy#createResponseWriter().
1670+
// See also ViewHandler#initView() and FaceletViewHandlingStrategy#renderView().
16711671
encoding = (String) context.getExternalContext().getSessionMap().get(CHARACTER_ENCODING_KEY);
16721672

16731673
if (encoding != null && LOGGER.isLoggable(FINEST)) {

0 commit comments

Comments
 (0)