类 MessageTag
- java.lang.Object
- javax.servlet.jsp.tagext.TagSupport
- org.springframework.web.servlet.tags.RequestContextAwareTag
- org.springframework.web.servlet.tags.HtmlEscapingAwareTag
- org.springframework.web.servlet.tags.MessageTag
- 所有已实现的接口:
Serializable
,IterationTag
,JspTag
,Tag
,TryCatchFinally
,ArgumentAware
- 直接已知子类:
ThemeTag
public class MessageTag extends HtmlEscapingAwareTag implements ArgumentAware
The<message>
tag looks up a message in the scope of this page. Messages are resolved using the ApplicationContext and thus support internationalization.Detects an HTML escaping setting, either on this tag instance, the page level, or the
web.xml
level. Can also apply JavaScript escaping.If "code" isn't set or cannot be resolved, "text" will be used as default message. Thus, this tag can also be used for HTML escaping of any texts.
Message arguments can be specified via the
arguments
attribute or by using nested<spring:argument>
tags.Attribute Summary Attribute Required? Runtime Expression? Description arguments false true Set optional message arguments for this tag, as a (comma-)delimited String (each String argument can contain JSP EL), an Object array (used as argument array), or a single Object (used as single argument). argumentSeparator false true The separator character to be used for splitting the arguments string value; defaults to a 'comma' (','). code false true The code (key) to use when looking up the message. If code is not provided, the text attribute will be used. htmlEscape false true Set HTML escaping for this tag, as boolean value. Overrides the default HTML escaping setting for the current page. javaScriptEscape false true Set JavaScript escaping for this tag, as boolean value. Default is false. message false true A MessageSourceResolvable argument (direct or through JSP EL). Fits nicely when used in conjunction with Spring鈥檚 own validation error classes which all implement the MessageSourceResolvable interface. For example, this allows you to iterate over all of the errors in a form, passing each error (using a runtime expression) as the value of this 'message' attribute, thus effecting the easy display of such error messages. scope false true The scope to use when exporting the result to a variable. This attribute is only used when var is also set. Possible values are page, request, session and application. text false true Default text to output when a message for the given code could not be found. If both text and code are not set, the tag will output null. var false true The string to use when binding the result to the page, request, session or application scope. If not specified, the result gets outputted to the writer (i.e. typically directly to the JSP). - 作者:
- Rod Johnson, Juergen Hoeller, Nicholas Williams
- 另请参阅:
setCode(java.lang.String)
,setText(java.lang.String)
,HtmlEscapingAwareTag.setHtmlEscape(boolean)
,setJavaScriptEscape(boolean)
,HtmlEscapeTag.setDefaultHtmlEscape(boolean)
,WebUtils.HTML_ESCAPE_CONTEXT_PARAM
,ArgumentTag
, 序列化表格
字段概要
字段 修饰符和类型 字段 说明 static String
DEFAULT_ARGUMENT_SEPARATOR
Default separator for splitting an arguments String: a comma (",").从类继承的字段 org.springframework.web.servlet.tags.RequestContextAwareTag
logger, REQUEST_CONTEXT_PAGE_ATTRIBUTE
从类继承的字段 javax.servlet.jsp.tagext.TagSupport
id, pageContext
从接口继承的字段 javax.servlet.jsp.tagext.IterationTag
EVAL_BODY_AGAIN
从接口继承的字段 javax.servlet.jsp.tagext.Tag
EVAL_BODY_INCLUDE, EVAL_PAGE, SKIP_BODY, SKIP_PAGE
构造器概要
构造器 构造器 说明 MessageTag()
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 void
addArgument(Object argument)
Callback hook for nested spring:argument tags to pass their value to the parent tag.int
doEndTag()
Resolves the message, escapes it if demanded, and writes it to the page (or exposes it as variable).protected int
doStartTagInternal()
Called by doStartTag to perform the actual work.protected MessageSource
getMessageSource()
Use the current RequestContext's application context as MessageSource.protected String
getNoSuchMessageExceptionDescription(NoSuchMessageException ex)
Return default exception message.void
release()
protected Object[]
resolveArguments(Object arguments)
Resolve the given arguments Object into an arguments array.protected String
resolveMessage()
Resolve the specified message into a concrete message String.void
setArguments(Object arguments)
Set optional message arguments for this tag, as a comma-delimited String (each String argument can contain JSP EL), an Object array (used as argument array), or a single Object (used as single argument).void
setArgumentSeparator(String argumentSeparator)
Set the separator to use for splitting an arguments String.void
setCode(String code)
Set the message code for this tag.void
setJavaScriptEscape(boolean javaScriptEscape)
Set JavaScript escaping for this tag, as boolean value.void
setMessage(MessageSourceResolvable message)
Set the MessageSourceResolvable for this tag.void
setScope(String scope)
Set the scope to export the variable to.void
setText(String text)
Set the message text for this tag.void
setVar(String var)
Set PageContext attribute name under which to expose a variable that contains the resolved message.protected void
writeMessage(String msg)
Write the message to the page.从类继承的方法 org.springframework.web.servlet.tags.HtmlEscapingAwareTag
htmlEscape, isDefaultHtmlEscape, isHtmlEscape, isResponseEncodedHtmlEscape, setHtmlEscape
从类继承的方法 org.springframework.web.servlet.tags.RequestContextAwareTag
doCatch, doFinally, doStartTag, getRequestContext
从类继承的方法 javax.servlet.jsp.tagext.TagSupport
doAfterBody, findAncestorWithClass, getId, getParent, getValue, getValues, removeValue, setId, setPageContext, setParent, setValue
字段详细资料
DEFAULT_ARGUMENT_SEPARATOR
public static final String DEFAULT_ARGUMENT_SEPARATOR
Default separator for splitting an arguments String: a comma (",").- 另请参阅:
- 常量字段值
构造器详细资料
MessageTag
public MessageTag()
方法详细资料
setMessage
public void setMessage(MessageSourceResolvable message)
Set the MessageSourceResolvable for this tag.If a MessageSourceResolvable is specified, it effectively overrides any code, arguments or text specified on this tag.
setArguments
public void setArguments(Object arguments)
Set optional message arguments for this tag, as a comma-delimited String (each String argument can contain JSP EL), an Object array (used as argument array), or a single Object (used as single argument).
setArgumentSeparator
public void setArgumentSeparator(String argumentSeparator)
Set the separator to use for splitting an arguments String. Default is a comma (",").
addArgument
public void addArgument(@Nullable Object argument) throws JspTagException
从接口复制的说明:ArgumentAware
Callback hook for nested spring:argument tags to pass their value to the parent tag.- 指定者:
addArgument
在接口中ArgumentAware
- 参数:
argument
- the result of the nestedspring:argument
tag- 抛出:
JspTagException
setVar
public void setVar(String var)
Set PageContext attribute name under which to expose a variable that contains the resolved message.
setScope
public void setScope(String scope)
Set the scope to export the variable to. Default is SCOPE_PAGE ("page").
setJavaScriptEscape
public void setJavaScriptEscape(boolean javaScriptEscape) throws JspException
Set JavaScript escaping for this tag, as boolean value. Default is "false".- 抛出:
JspException
doStartTagInternal
protected final int doStartTagInternal() throws JspException, IOException
从类复制的说明:RequestContextAwareTag
Called by doStartTag to perform the actual work.- 指定者:
doStartTagInternal
在类中RequestContextAwareTag
- 返回:
- same as TagSupport.doStartTag
- 抛出:
JspException
IOException
- 另请参阅:
TagSupport.doStartTag()
doEndTag
public int doEndTag() throws JspException
Resolves the message, escapes it if demanded, and writes it to the page (or exposes it as variable).
release
public void release()
- 指定者:
release
在接口中Tag
- 覆盖:
release
在类中TagSupport
resolveMessage
protected String resolveMessage() throws JspException, NoSuchMessageException
Resolve the specified message into a concrete message String. The returned message String should be unescaped.
resolveArguments
@Nullable protected Object[] resolveArguments(@Nullable Object arguments) throws JspException
Resolve the given arguments Object into an arguments array.- 参数:
arguments
- the specified arguments Object- 返回:
- the resolved arguments as array
- 抛出:
JspException
- if argument conversion failed- 另请参阅:
setArguments(java.lang.Object)
writeMessage
protected void writeMessage(String msg) throws IOException
Write the message to the page.Can be overridden in subclasses, e.g. for testing purposes.
- 参数:
msg
- the message to write- 抛出:
IOException
- if writing failed
getMessageSource
protected MessageSource getMessageSource()
Use the current RequestContext's application context as MessageSource.
getNoSuchMessageExceptionDescription
protected String getNoSuchMessageExceptionDescription(NoSuchMessageException ex)
Return default exception message.