Skip to content

Allow hiding model attributes in redirects #299

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 3.1-dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public class ThymeleafViewResolver

private boolean redirectContextRelative = true;
private boolean redirectHttp10Compatible = true;
private boolean redirectExposeModelAttributes = true;

private boolean alwaysProcessRedirectAndForward = true;

Expand Down Expand Up @@ -523,8 +524,35 @@ public void setRedirectHttp10Compatible(final boolean redirectHttp10Compatible)
public boolean isRedirectHttp10Compatible() {
return this.redirectHttp10Compatible;
}




/**
* <p>
* Set whether model attributes should be appended to the URI, when performing a redirection.
* </p>
*
* @param redirectExposeModelAttributes true if model attributes should be appended to the redirect URI,
* false if not
* @see RedirectView#setExposeModelAttributes(boolean)
*/
public void setRedirectExposeModelAttributes(final boolean redirectExposeModelAttributes) {
this.redirectExposeModelAttributes = redirectExposeModelAttributes;
}


/**
* <p>
* Return whether model attributes should be appended to the URI, when performing a redirection.
* </p>
*
* @return whether model attributes should be appended to the URI, when performing a redirection.
* @see RedirectView#setExposeModelAttributes(boolean)
*
*/
public boolean shouldRedirectExposeModelAttributes() {
return this.redirectExposeModelAttributes;
}


/**
* <p>
Expand Down Expand Up @@ -775,7 +803,7 @@ protected View createView(final String viewName, final Locale locale) throws Exc
if (viewName.startsWith(REDIRECT_URL_PREFIX)) {
vrlogger.trace("[THYMELEAF] View \"{}\" is a redirect, and will not be handled directly by ThymeleafViewResolver.", viewName);
final String redirectUrl = viewName.substring(REDIRECT_URL_PREFIX.length(), viewName.length());
final RedirectView view = new RedirectView(redirectUrl, isRedirectContextRelative(), isRedirectHttp10Compatible());
final RedirectView view = new RedirectView(redirectUrl, isRedirectContextRelative(), isRedirectHttp10Compatible(), shouldRedirectExposeModelAttributes());
return (View) getApplicationContext().getAutowireCapableBeanFactory().initializeBean(view, REDIRECT_URL_PREFIX);
}
// Process forwards (to JSP resources)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public class ThymeleafViewResolver

private boolean redirectContextRelative = true;
private boolean redirectHttp10Compatible = true;
private boolean redirectExposeModelAttributes = true;

private boolean alwaysProcessRedirectAndForward = true;

Expand Down Expand Up @@ -525,6 +526,33 @@ public boolean isRedirectHttp10Compatible() {
}


/**
* <p>
* Set whether model attributes should be appended to the URI, when performing a redirection.
* </p>
*
* @param redirectExposeModelAttributes true if model attributes should be appended to the redirect URI,
* false if not
* @see RedirectView#setExposeModelAttributes(boolean)
*/
public void setRedirectExposeModelAttributes(final boolean redirectExposeModelAttributes) {
this.redirectExposeModelAttributes = redirectExposeModelAttributes;
}


/**
* <p>
* Return whether model attributes should be appended to the URI, when performing a redirection.
* </p>
*
* @return whether model attributes should be appended to the URI, when performing a redirection.
* @see RedirectView#setExposeModelAttributes(boolean)
*
*/
public boolean shouldRedirectExposeModelAttributes() {
return this.redirectExposeModelAttributes;
}


/**
* <p>
Expand Down Expand Up @@ -775,7 +803,7 @@ protected View createView(final String viewName, final Locale locale) throws Exc
if (viewName.startsWith(REDIRECT_URL_PREFIX)) {
vrlogger.trace("[THYMELEAF] View \"{}\" is a redirect, and will not be handled directly by ThymeleafViewResolver.", viewName);
final String redirectUrl = viewName.substring(REDIRECT_URL_PREFIX.length(), viewName.length());
final RedirectView view = new RedirectView(redirectUrl, isRedirectContextRelative(), isRedirectHttp10Compatible());
final RedirectView view = new RedirectView(redirectUrl, isRedirectContextRelative(), isRedirectHttp10Compatible(), shouldRedirectExposeModelAttributes());
return (View) getApplicationContext().getAutowireCapableBeanFactory().initializeBean(view, REDIRECT_URL_PREFIX);
}
// Process forwards (to JSP resources)
Expand Down