Class MessageTag
java.lang.Object
org.javalite.activeweb.freemarker.FreeMarkerTag
org.javalite.activeweb.freemarker.MessageTag
- All Implemented Interfaces:
freemarker.template.TemplateDirectiveModel
,freemarker.template.TemplateModel
,RequestAccess
The message tag is designed to display messages in view templates. Message values are defined in resource bundle called
"javalite_messages". This means that this tag will be looking for file called
javalite_messages.properties
as default
name and others, such as javalite_messages_fr_FR.properties
in case French locale was specified.
Examples:
Simple usage
Given that there is a filejavalite_messages.properties
with content:greeting=Hello!and tag code:
<@message key="greeting"/>then the output will be:
Hello!
Message with parameters
Lets say a message in resource bundle is declared like this:meeting=Meeting will take place on {0} at {1}
You can then specify the tag with parameters:
<@message key="meeting" param0="Wednesday" param1="2:00 PM"/>
When a view template renders, the outcome will be:
Meeting will take place on Wednesday at 2:00 PM
Defaulting to key if value not found
In case a resource bundle does not have a key specified, the key is rendered as value verbatim:
<@message key="greeting"/>
The output:
greeting
Detection of locale from request
If there is a locale on the request supplied by the agent, then this locale is automatically picked up by this tag. For instance, if a browser supplies locale "fr_FR" and there is a corresponding resource bundle: "javalite_messages_fr_FR.properties", with this property:
greeting=Bonjour!
then this tag:
<@message key="greeting"/>will produce:
Bonjour!
Overriding request locale
There is a "locale" argument you can pass to the tag to override the locale from request:<@message key="greeting" locale="de_DE"/>
- Author:
- Igor Polevoy: 8/15/12 3:50 PM
-
Field Summary
Fields inherited from interface org.javalite.activeweb.RequestAccess
LOGGER
Fields inherited from interface freemarker.template.TemplateModel
NOTHING
-
Constructor Summary
-
Method Summary
Methods inherited from class org.javalite.activeweb.freemarker.FreeMarkerTag
execute, get, getAllVariables, getContextPath, getUnwrapped, getUnwrapped, logger, overrideContext, process, session, sessionObject, validateParamsPresence
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.javalite.activeweb.RequestAccess
appContext, context, cookie, cookies, cookieValue, exists, format, getId, getLocale, getRequestHost, getRequestPort, getRequestProperties, getRequestProtocol, getRoute, header, headers, host, ipAddress, ipForwardedFor, isDelete, isGet, isHead, isMethod, isMultipartContent, isPost, isPut, isXhr, locale, method, param, param, params, params, params, params1st, params1st, path, port, protocol, queryString, remoteAddress, remoteHost, requestHas, servletPath, session, session, uri, url, userAgent, xhr
-
Constructor Details
-
MessageTag
public MessageTag()
-
-
Method Details
-
render
Description copied from class:FreeMarkerTag
Implement this method ina concrete subclass.- Specified by:
render
in classFreeMarkerTag
- Parameters:
params
- this is a list of parameters as provided to tag in HTML.body
- body of tagwriter
- writer to write output to.- Throws:
Exception
- if any
-