public class MessageTag extends HtmlEscapingAwareTag implements ArgumentAware
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.
setCode(java.lang.String),
setText(java.lang.String),
HtmlEscapingAwareTag.setHtmlEscape(boolean),
setJavaScriptEscape(boolean),
HtmlEscapeTag.setDefaultHtmlEscape(boolean),
WebUtils.HTML_ESCAPE_CONTEXT_PARAM,
ArgumentTag,
Serialized Form| Modifier and Type | Field and Description |
|---|---|
static String |
DEFAULT_ARGUMENT_SEPARATOR
Default separator for splitting an arguments String: a comma (",")
|
logger, REQUEST_CONTEXT_PAGE_ATTRIBUTEid, pageContextEVAL_BODY_AGAINEVAL_BODY_INCLUDE, EVAL_PAGE, SKIP_BODY, SKIP_PAGE| Constructor and Description |
|---|
MessageTag() |
| Modifier and Type | Method and Description |
|---|---|
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 org.springframework.context.MessageSource |
getMessageSource()
Use the current RequestContext's application context as MessageSource.
|
protected String |
getNoSuchMessageExceptionDescription(org.springframework.context.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(org.springframework.context.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.
|
isDefaultHtmlEscape, isHtmlEscape, setHtmlEscapedoCatch, doFinally, doStartTag, getRequestContextdoAfterBody, findAncestorWithClass, getId, getParent, getValue, getValues, removeValue, setId, setPageContext, setParent, setValuepublic static final String DEFAULT_ARGUMENT_SEPARATOR
public void setMessage(org.springframework.context.MessageSourceResolvable message)
If a MessageSourceResolvable is specified, it effectively overrides any code, arguments or text specified on this tag.
public void setCode(String code)
public void setArguments(Object arguments)
public void setArgumentSeparator(String argumentSeparator)
setArguments(java.lang.Object)public void addArgument(Object argument) throws JspTagException
ArgumentAwareaddArgument in interface ArgumentAwareargument - the result of the nested spring:argument tagJspTagExceptionpublic void setText(String text)
public void setVar(String var)
public void setScope(String scope)
setVar(java.lang.String),
TagUtils.SCOPE_PAGE,
JspContext.setAttribute(java.lang.String, java.lang.Object)public void setJavaScriptEscape(boolean javaScriptEscape)
throws JspException
JspExceptionprotected final int doStartTagInternal()
throws JspException,
IOException
RequestContextAwareTagdoStartTagInternal in class RequestContextAwareTagJspExceptionIOExceptionTagSupport.doStartTag()public int doEndTag()
throws JspException
doEndTag in interface TagdoEndTag in class TagSupportJspExceptionresolveMessage(),
HtmlUtils.htmlEscape(String),
JavaScriptUtils.javaScriptEscape(String),
writeMessage(String)public void release()
release in interface Tagrelease in class TagSupportprotected String resolveMessage() throws JspException, org.springframework.context.NoSuchMessageException
JspExceptionorg.springframework.context.NoSuchMessageExceptionprotected Object[] resolveArguments(Object arguments) throws JspException
arguments - the specified arguments ObjectJspException - if argument conversion failedsetArguments(java.lang.Object)protected void writeMessage(String msg) throws IOException
Can be overridden in subclasses, e.g. for testing purposes.
msg - the message to writeIOException - if writing failedprotected org.springframework.context.MessageSource getMessageSource()
protected String getNoSuchMessageExceptionDescription(org.springframework.context.NoSuchMessageException ex)