public class OpenmrsMessageTag extends OpenmrsHtmlEscapingAwareTag
As spring:message tag, this also retrieves the message from bundle with the given code, but (in addition) this tag uses its body text when the code cannot be resolved. If the body value also is not specified, the value of the text attribute is used. If there is no message in the bundle and no text attribute value or tag body text, then the message code is displayed, if it is set; otherwise null. If both text attribute and body text are present (shouldn't happen, but could by mistake), then this tag uses the body text before checking the text attribute. With this tag user can define default text for a locale other than the system default by using locale attribute. If locale attribute is not specified, then the system default locale (e.g., "en") will be used. HTML escaping is also supported by this tag.
This tag also supports customization of messages writing behavior. To change its default behavior, set the TagWriterBehavior
property with a custom implementation of the TagMessageWriterBehavior
interface.
For example, if you put the following:
<openmrs:message code="wrong.code" >Some text </openmrs:message>
and there is no message that can be resolved by given code, then output will be "Some text". You may also specify the fallback in spring-ish style using text attribute as follows:
<openmrs:message code="wrong.code" text="Some other text" />
Using locale attribute of tag you can specify the locale of fallback text provided by message tag. You could write the tag like:
<openmrs:message code="foo.greeting" locale="fr">Bonjour</openmrs:message>meaning that the message supplied with the tag is in the "fr" locale. If the user is viewing in English, then the message within the English message bundle with the code foo.greeting would be displayed.
Modifier and Type | Field and Description |
---|---|
static String |
DEFAULT_ARGUMENT_SEPARATOR
Default separator for splitting an arguments String: a comma (",")
|
static TagMessageWriterBehavior |
DEFAULT_WRITER_BEHAVIOUR
Default behavior used for writing resolved messages into output
|
static TagMessageWriterBehavior |
tagWriterBehavior
Tag writing behavior instance used for customization of resolved messages rendering
|
logger
Constructor and Description |
---|
OpenmrsMessageTag() |
Modifier and Type | Method and Description |
---|---|
protected int |
doEndTagInternal()
Called by doEndTag 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.
|
protected Object[] |
resolveArguments(Object arguments) |
protected String |
resolveMessage()
Resolve the specified message or code or text or tag body into a concrete message string.
|
void |
setArguments(Object arguments) |
void |
setArgumentSeparator(String argumentSeparator) |
void |
setCode(String code)
Set the message code for this tag.
|
void |
setJavaScriptEscape(String javaScriptEscape)
Set JavaScript escaping for this tag, as boolean value.
|
void |
setLocale(String locale)
Sets the locale of the supplied message.
|
void |
setMessage(Object message) |
void |
setScope(String scope) |
static void |
setTagWriterBehavior(TagMessageWriterBehavior tagWriterBehavior)
Sets tag writer behavior to customize rendering of resolved messages
|
void |
setText(String text)
Set the message text for this tag.
|
void |
setVar(String var) |
protected void |
writeMessage(String message)
Writes the message to the page.
|
isDefaultHtmlEscape, isHtmlEscape, setHtmlEscape
doEndTag, doStartTag, getRequestContext
doAfterBody, doInitBody, getBodyContent, getPreviousOut, release, setBodyContent
findAncestorWithClass, getId, getParent, getValue, getValues, removeValue, setId, setPageContext, setParent, setValue
public static final String DEFAULT_ARGUMENT_SEPARATOR
public static final TagMessageWriterBehavior DEFAULT_WRITER_BEHAVIOUR
public static TagMessageWriterBehavior tagWriterBehavior
public void setMessage(Object message)
MessageTag.setMessage(Object)
public void setCode(String code)
public void setArguments(Object arguments)
MessageTag.setArguments(Object)
public void setArgumentSeparator(String argumentSeparator)
MessageTag.setArgumentSeparator(String)
public void setText(String text)
public void setVar(String var)
MessageTag.setVar(String)
public void setScope(String scope)
MessageTag.setScope(String)
public void setLocale(String locale)
locale
- the locale string to setpublic void setJavaScriptEscape(String javaScriptEscape) throws javax.servlet.jsp.JspException
javax.servlet.jsp.JspException
protected int doEndTagInternal() throws javax.servlet.jsp.JspException, IOException
OpenmrsRequestContextAwareBodyTag
doEndTagInternal
in class OpenmrsRequestContextAwareBodyTag
javax.servlet.jsp.JspException
IOException
MessageTag.doStartTagInternal()
protected String resolveMessage() throws javax.servlet.jsp.JspException
javax.servlet.jsp.JspException
protected Object[] resolveArguments(Object arguments) throws javax.servlet.jsp.JspException
javax.servlet.jsp.JspException
MessageTag.resolveArguments(Object)
protected void writeMessage(String message) throws IOException
message
- the message to writeIOException
- if writing error occursprotected org.springframework.context.MessageSource getMessageSource()
protected String getNoSuchMessageExceptionDescription(org.springframework.context.NoSuchMessageException ex)
public static void setTagWriterBehavior(TagMessageWriterBehavior tagWriterBehavior)
tagWriterBehavior
- the tagWriterBehavior to setCopyright © 2018 OpenMRS LLC.. All Rights Reserved.