lenient evaluation of boolean 'true' attribute expressions in JSP form tag library (SPR-6790)
This commit is contained in:
parent
41ecbc6814
commit
4d897e7ab5
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -17,7 +17,6 @@
|
|||
package org.springframework.web.servlet.tags.form;
|
||||
|
||||
import java.beans.PropertyEditor;
|
||||
|
||||
import javax.servlet.jsp.JspException;
|
||||
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
|
@ -55,6 +54,18 @@ public abstract class AbstractFormTag extends HtmlEscapingAwareTag {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Evaluate the supplied value for the supplied attribute name. If the supplied value
|
||||
* is <code>null</code> then <code>false</code> is returned, otherwise evaluation is
|
||||
* handled using {@link ExpressionEvaluationUtils#evaluate(String, String, javax.servlet.jsp.PageContext)},
|
||||
* with subsequent matching against <code>Boolean.TRUE</code> and <code>Boolean.valueOf</code>.
|
||||
*/
|
||||
protected boolean evaluateBoolean(String attributeName, String value) throws JspException {
|
||||
Object evaluated = ExpressionEvaluationUtils.evaluate(attributeName, value, this.pageContext);
|
||||
return (Boolean.TRUE.equals(evaluated) ||
|
||||
(evaluated instanceof String && Boolean.valueOf((String) evaluated)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Optionally writes the supplied value under the supplied attribute name into the supplied
|
||||
* {@link TagWriter}. In this case, the supplied value is {@link #evaluate evaluated} first
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -192,7 +192,7 @@ public abstract class AbstractHtmlInputElementTag extends AbstractHtmlElementTag
|
|||
* Is the current HTML tag disabled?
|
||||
*/
|
||||
protected boolean isDisabled() throws JspException {
|
||||
return "true".equals(evaluate(DISABLED_ATTRIBUTE, getDisabled()));
|
||||
return evaluateBoolean(DISABLED_ATTRIBUTE, getDisabled());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -202,7 +202,7 @@ public abstract class AbstractHtmlInputElementTag extends AbstractHtmlElementTag
|
|||
* not affected by them since their values don't change (only their status does.)
|
||||
*/
|
||||
protected boolean isReadonly() throws JspException {
|
||||
return "true".equals(evaluate(READONLY_ATTRIBUTE, getReadonly()));
|
||||
return evaluateBoolean(READONLY_ATTRIBUTE, getReadonly());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -126,8 +126,8 @@ public class OptionTag extends AbstractHtmlElementBodyTag implements BodyTag {
|
|||
* Is the current HTML tag disabled?
|
||||
* @return <code>true</code> if this tag is disabled
|
||||
*/
|
||||
protected boolean isDisabled() {
|
||||
return "true".equals(getDisabled());
|
||||
protected boolean isDisabled() throws JspException {
|
||||
return evaluateBoolean(DISABLED_ATTRIBUTE, getDisabled());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -19,7 +19,6 @@ package org.springframework.web.servlet.tags.form;
|
|||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.jsp.JspException;
|
||||
|
||||
import org.springframework.beans.BeanWrapper;
|
||||
|
|
@ -258,7 +257,7 @@ class OptionWriter {
|
|||
/**
|
||||
* Determine whether the option fields should be disabled.
|
||||
*/
|
||||
protected boolean isOptionDisabled() {
|
||||
protected boolean isOptionDisabled() throws JspException {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -138,8 +138,8 @@ public class OptionsTag extends AbstractHtmlElementTag {
|
|||
* Is the current HTML tag disabled?
|
||||
* @return <code>true</code> if this tag is disabled
|
||||
*/
|
||||
protected boolean isDisabled() {
|
||||
return "true".equals(getDisabled());
|
||||
protected boolean isDisabled() throws JspException {
|
||||
return evaluateBoolean("disabled", getDisabled());
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -149,7 +149,7 @@ public class OptionsTag extends AbstractHtmlElementTag {
|
|||
Object items = getItems();
|
||||
Object itemsObject = null;
|
||||
if (items != null) {
|
||||
itemsObject = (items instanceof String ? evaluate("items", (String) items) : items);
|
||||
itemsObject = (items instanceof String ? evaluate("items", items) : items);
|
||||
} else {
|
||||
Class<?> selectTagBoundType = ((SelectTag) findAncestorWithClass(this, SelectTag.class))
|
||||
.getBindStatus().getValueType();
|
||||
|
|
@ -204,7 +204,7 @@ public class OptionsTag extends AbstractHtmlElementTag {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected boolean isOptionDisabled() {
|
||||
protected boolean isOptionDisabled() throws JspException {
|
||||
return isDisabled();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -18,7 +18,6 @@ package org.springframework.web.servlet.tags.form;
|
|||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.jsp.JspException;
|
||||
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
|
@ -247,12 +246,11 @@ public class SelectTag extends AbstractHtmlInputElementTag {
|
|||
|
||||
private boolean isMultiple() throws JspException {
|
||||
Object multiple = getMultiple();
|
||||
if (Boolean.TRUE.equals(multiple) || "true".equals(multiple) || "multiple".equals(multiple)) {
|
||||
if (Boolean.TRUE.equals(multiple) || "multiple".equals(multiple)) {
|
||||
return true;
|
||||
}
|
||||
else if (this.multiple instanceof String) {
|
||||
Object evaluatedValue = evaluate("multiple", multiple);
|
||||
return Boolean.TRUE.equals(evaluatedValue);
|
||||
return evaluateBoolean("multiple", (String) multiple);
|
||||
}
|
||||
return forceMultiple();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue