Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
57fe16e1
S
spring-framework
项目概览
爱吃血肠
/
spring-framework
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
spring-framework
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
57fe16e1
编写于
10月 21, 2011
作者:
R
Rossen Stoyanchev
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
SPR-8755 Add Button tag.
上级
fd97c8d7
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
270 addition
and
0 deletion
+270
-0
org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/tags/form/ButtonTag.java
.../org/springframework/web/servlet/tags/form/ButtonTag.java
+147
-0
org.springframework.web.servlet/src/main/resources/META-INF/spring-form.tld
...k.web.servlet/src/main/resources/META-INF/spring-form.tld
+32
-0
org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/tags/form/ButtonTagTests.java
...springframework/web/servlet/tags/form/ButtonTagTests.java
+91
-0
未找到文件。
org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/tags/form/ButtonTag.java
0 → 100644
浏览文件 @
57fe16e1
/*
* Copyright 2002-2011 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.springframework.web.servlet.tags.form
;
import
javax.servlet.jsp.JspException
;
import
org.springframework.web.servlet.support.RequestDataValueProcessor
;
/**
* An HTML button tag. This tag is provided for completeness if the application
* relies on a {@link RequestDataValueProcessor}.
*
* @author Rossen Stoyanchev
* @since 3.1
*/
@SuppressWarnings
(
"serial"
)
public
class
ButtonTag
extends
AbstractHtmlElementTag
{
/**
* The name of the '<code>disabled</code>' attribute.
*/
public
static
final
String
DISABLED_ATTRIBUTE
=
"disabled"
;
private
TagWriter
tagWriter
;
private
String
name
;
private
String
value
;
private
String
disabled
;
/**
* Set the value of the '<code>name</code>' attribute.
*/
public
String
getName
()
{
return
name
;
}
/**
* Get the value of the '<code>name</code>' attribute.
*/
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
/**
* Get the value of the '<code>value</code>' attribute.
*/
public
String
getValue
()
{
return
this
.
value
;
}
/**
* Set the value of the '<code>value</code>' attribute.
*/
public
void
setValue
(
String
value
)
{
this
.
value
=
value
;
}
/**
* Get the value of the '<code>disabled</code>' attribute.
*/
public
String
getDisabled
()
{
return
this
.
disabled
;
}
/**
* Set the value of the '<code>disabled</code>' attribute.
* May be a runtime expression.
*/
public
void
setDisabled
(
String
disabled
)
{
this
.
disabled
=
disabled
;
}
@Override
protected
int
writeTagContent
(
TagWriter
tagWriter
)
throws
JspException
{
tagWriter
.
startTag
(
"button"
);
writeDefaultAttributes
(
tagWriter
);
tagWriter
.
writeAttribute
(
"type"
,
getType
());
writeValue
(
tagWriter
);
if
(
isDisabled
())
{
tagWriter
.
writeAttribute
(
DISABLED_ATTRIBUTE
,
"disabled"
);
}
tagWriter
.
forceBlock
();
this
.
tagWriter
=
tagWriter
;
return
EVAL_BODY_INCLUDE
;
}
/**
* Is the current HTML tag disabled?
*/
protected
boolean
isDisabled
()
throws
JspException
{
return
evaluateBoolean
(
DISABLED_ATTRIBUTE
,
getDisabled
());
}
/**
* Writes the '<code>value</code>' attribute to the supplied {@link TagWriter}.
* Subclasses may choose to override this implementation to control exactly
* when the value is written.
*/
protected
void
writeValue
(
TagWriter
tagWriter
)
throws
JspException
{
String
valueToUse
=
(
getValue
()
!=
null
)
?
getValue
()
:
getDefaultValue
();
tagWriter
.
writeAttribute
(
"value"
,
processFieldValue
(
getName
(),
valueToUse
,
getType
()));
}
/**
* Return the default value.
*
* @return The default value if none supplied.
*/
protected
String
getDefaultValue
()
{
return
"Submit"
;
}
/**
* Get the value of the '<code>type</code>' attribute. Subclasses
* can override this to change the type of '<code>input</code>' element
* rendered. Default value is '<code>submit</code>'.
*/
protected
String
getType
()
{
return
"submit"
;
}
/**
* Closes the '<code>button</code>' block tag.
*/
@Override
public
int
doEndTag
()
throws
JspException
{
this
.
tagWriter
.
endTag
();
return
EVAL_PAGE
;
}
}
org.springframework.web.servlet/src/main/resources/META-INF/spring-form.tld
浏览文件 @
57fe16e1
...
...
@@ -2370,4 +2370,36 @@
<dynamic-attributes>
true
</dynamic-attributes>
</tag>
<tag>
<description>
Renders an HTML 'button' tag.
</description>
<name>
button
</name>
<tag-class>
org.springframework.web.servlet.tags.form.ButtonTag
</tag-class>
<body-content>
JSP
</body-content>
<attribute>
<description>
HTML Standard Attribute
</description>
<name>
id
</name>
<required>
false
</required>
<rtexprvalue>
true
</rtexprvalue>
</attribute>
<attribute>
<description>
The name attribute for the HTML button tag
</description>
<name>
name
</name>
<required>
false
</required>
<rtexprvalue>
true
</rtexprvalue>
</attribute>
<attribute>
<description>
The value attribute for the HTML button tag
</description>
<name>
value
</name>
<required>
false
</required>
<rtexprvalue>
true
</rtexprvalue>
</attribute>
<attribute>
<description>
HTML Optional Attribute. Setting the value of this attribute to 'true' (without the quotes) will disable the HTML element.
</description>
<name>
disabled
</name>
<required>
false
</required>
<rtexprvalue>
true
</rtexprvalue>
</attribute>
<dynamic-attributes>
true
</dynamic-attributes>
</tag>
</taglib>
org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/tags/form/ButtonTagTests.java
0 → 100644
浏览文件 @
57fe16e1
/*
* Copyright 2002-2011 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.springframework.web.servlet.tags.form
;
import
java.io.Writer
;
import
javax.servlet.jsp.tagext.Tag
;
import
org.springframework.beans.TestBean
;
/**
* @author Rossen Stoyanchev
*/
public
class
ButtonTagTests
extends
AbstractFormTagTests
{
private
ButtonTag
tag
;
protected
void
onSetUp
()
{
this
.
tag
=
createTag
(
getWriter
());
this
.
tag
.
setParent
(
getFormTag
());
this
.
tag
.
setPageContext
(
getPageContext
());
this
.
tag
.
setId
(
"My Id"
);
this
.
tag
.
setName
(
"My Name"
);
this
.
tag
.
setValue
(
"My Button"
);
}
public
void
testButtonTag
()
throws
Exception
{
assertEquals
(
Tag
.
EVAL_BODY_INCLUDE
,
this
.
tag
.
doStartTag
());
assertEquals
(
Tag
.
EVAL_PAGE
,
this
.
tag
.
doEndTag
());
String
output
=
getOutput
();
assertTagOpened
(
output
);
assertTagClosed
(
output
);
assertContainsAttribute
(
output
,
"id"
,
"My Id"
);
assertContainsAttribute
(
output
,
"name"
,
"My Name"
);
assertContainsAttribute
(
output
,
"type"
,
"submit"
);
assertContainsAttribute
(
output
,
"value"
,
"My Button"
);
assertAttributeNotPresent
(
output
,
"disabled"
);
}
public
void
testDisabled
()
throws
Exception
{
this
.
tag
.
setDisabled
(
"true"
);
this
.
tag
.
doStartTag
();
this
.
tag
.
doEndTag
();
String
output
=
getOutput
();
assertTagOpened
(
output
);
assertTagClosed
(
output
);
assertContainsAttribute
(
output
,
"disabled"
,
"disabled"
);
}
@Override
protected
TestBean
createTestBean
()
{
return
new
TestBean
();
}
protected
final
void
assertTagClosed
(
String
output
)
{
assertTrue
(
"Tag not closed properly"
,
output
.
endsWith
(
"</button>"
));
}
protected
final
void
assertTagOpened
(
String
output
)
{
assertTrue
(
"Tag not opened properly"
,
output
.
startsWith
(
"<button "
));
}
@SuppressWarnings
(
"serial"
)
protected
ButtonTag
createTag
(
final
Writer
writer
)
{
return
new
ButtonTag
()
{
protected
TagWriter
createTagWriter
()
{
return
new
TagWriter
(
writer
);
}
};
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录