Skip to content

Commit 6d75732

Browse files
committed
FormTag skips rendering of hidden fields in case of empty Map
Issue: SPR-16498
1 parent de7ff55 commit 6d75732

File tree

1 file changed

+5
-3
lines changed
  • spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form

1 file changed

+5
-3
lines changed

Diff for: spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/FormTag.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -28,6 +28,7 @@
2828
import org.springframework.beans.PropertyAccessor;
2929
import org.springframework.core.Conventions;
3030
import org.springframework.http.HttpMethod;
31+
import org.springframework.util.CollectionUtils;
3132
import org.springframework.util.ObjectUtils;
3233
import org.springframework.util.StringUtils;
3334
import org.springframework.web.servlet.support.RequestDataValueProcessor;
@@ -666,7 +667,7 @@ private String processAction(String action) {
666667
public int doEndTag() throws JspException {
667668
RequestDataValueProcessor processor = getRequestContext().getRequestDataValueProcessor();
668669
ServletRequest request = this.pageContext.getRequest();
669-
if ((processor != null) && (request instanceof HttpServletRequest)) {
670+
if (processor != null && request instanceof HttpServletRequest) {
670671
writeHiddenFields(processor.getExtraHiddenFields((HttpServletRequest) request));
671672
}
672673
this.tagWriter.endTag();
@@ -677,7 +678,7 @@ public int doEndTag() throws JspException {
677678
* Writes the given values as hidden fields.
678679
*/
679680
private void writeHiddenFields(Map<String, String> hiddenFields) throws JspException {
680-
if (hiddenFields != null) {
681+
if (!CollectionUtils.isEmpty(hiddenFields)) {
681682
this.tagWriter.appendValue("<div>\n");
682683
for (String name : hiddenFields.keySet()) {
683684
this.tagWriter.appendValue("<input type=\"hidden\" ");
@@ -694,6 +695,7 @@ private void writeHiddenFields(Map<String, String> hiddenFields) throws JspExcep
694695
@Override
695696
public void doFinally() {
696697
super.doFinally();
698+
697699
this.pageContext.removeAttribute(MODEL_ATTRIBUTE_VARIABLE_NAME, PageContext.REQUEST_SCOPE);
698700
if (this.previousNestedPath != null) {
699701
// Expose previous nestedPath value.

0 commit comments

Comments
 (0)