FormTag skips rendering of hidden fields in case of empty Map
Issue: SPR-16498
This commit is contained in:
parent
de7ff556d9
commit
6d7573262e
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2016 the original author or authors.
|
* Copyright 2002-2018 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -28,6 +28,7 @@ import javax.servlet.jsp.PageContext;
|
||||||
import org.springframework.beans.PropertyAccessor;
|
import org.springframework.beans.PropertyAccessor;
|
||||||
import org.springframework.core.Conventions;
|
import org.springframework.core.Conventions;
|
||||||
import org.springframework.http.HttpMethod;
|
import org.springframework.http.HttpMethod;
|
||||||
|
import org.springframework.util.CollectionUtils;
|
||||||
import org.springframework.util.ObjectUtils;
|
import org.springframework.util.ObjectUtils;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
import org.springframework.web.servlet.support.RequestDataValueProcessor;
|
import org.springframework.web.servlet.support.RequestDataValueProcessor;
|
||||||
|
@ -666,7 +667,7 @@ public class FormTag extends AbstractHtmlElementTag {
|
||||||
public int doEndTag() throws JspException {
|
public int doEndTag() throws JspException {
|
||||||
RequestDataValueProcessor processor = getRequestContext().getRequestDataValueProcessor();
|
RequestDataValueProcessor processor = getRequestContext().getRequestDataValueProcessor();
|
||||||
ServletRequest request = this.pageContext.getRequest();
|
ServletRequest request = this.pageContext.getRequest();
|
||||||
if ((processor != null) && (request instanceof HttpServletRequest)) {
|
if (processor != null && request instanceof HttpServletRequest) {
|
||||||
writeHiddenFields(processor.getExtraHiddenFields((HttpServletRequest) request));
|
writeHiddenFields(processor.getExtraHiddenFields((HttpServletRequest) request));
|
||||||
}
|
}
|
||||||
this.tagWriter.endTag();
|
this.tagWriter.endTag();
|
||||||
|
@ -677,7 +678,7 @@ public class FormTag extends AbstractHtmlElementTag {
|
||||||
* Writes the given values as hidden fields.
|
* Writes the given values as hidden fields.
|
||||||
*/
|
*/
|
||||||
private void writeHiddenFields(Map<String, String> hiddenFields) throws JspException {
|
private void writeHiddenFields(Map<String, String> hiddenFields) throws JspException {
|
||||||
if (hiddenFields != null) {
|
if (!CollectionUtils.isEmpty(hiddenFields)) {
|
||||||
this.tagWriter.appendValue("<div>\n");
|
this.tagWriter.appendValue("<div>\n");
|
||||||
for (String name : hiddenFields.keySet()) {
|
for (String name : hiddenFields.keySet()) {
|
||||||
this.tagWriter.appendValue("<input type=\"hidden\" ");
|
this.tagWriter.appendValue("<input type=\"hidden\" ");
|
||||||
|
@ -694,6 +695,7 @@ public class FormTag extends AbstractHtmlElementTag {
|
||||||
@Override
|
@Override
|
||||||
public void doFinally() {
|
public void doFinally() {
|
||||||
super.doFinally();
|
super.doFinally();
|
||||||
|
|
||||||
this.pageContext.removeAttribute(MODEL_ATTRIBUTE_VARIABLE_NAME, PageContext.REQUEST_SCOPE);
|
this.pageContext.removeAttribute(MODEL_ATTRIBUTE_VARIABLE_NAME, PageContext.REQUEST_SCOPE);
|
||||||
if (this.previousNestedPath != null) {
|
if (this.previousNestedPath != null) {
|
||||||
// Expose previous nestedPath value.
|
// Expose previous nestedPath value.
|
||||||
|
|
Loading…
Reference in New Issue