Thymeleaf built-in object expression completeness

Here, the built-in expressions from Thymeleaf version 3.0 are collated
- Reference from Official Thymeleaf 3.0 Documentation , Articles 18 and 19

1. Expression Basic Object

Reference from Thymeleaf 3.0 Official Document Article 18

1.1 Base Object

#ctx: Context object

    ${#ctx.locale}
    ${#ctx.variableNames}
    ${#ctx.request}
    ${#ctx.response}
    ${#ctx.session}
    ${#ctx.servletContext}

#locale: Direct access to the content associated with the current request by java.util.Locale

    ${#locale}

1.2 Sessions

param: used to retrieve request parameters
The ${param.foo} is String[] with a foorequest parameter value, so ${param.foo[0]} is usually used to get the first value

    ${param.foo}              // Retrieve a string with the value of the request parameter'foo'[]
    ${param.size()}
    ${param.isEmpty()}
    ${param.containsKey('foo')}

Session: used to retrieve session properties

    ${session.foo}                 // Retrieving session property "foo"
    ${session.size()}
    ${session.isEmpty()}
    ${session.containsKey('foo')}

Application: used to retrieve application / servlet context properties

    ${application.foo}              // Retrieving the ServletContext property "foo"
    ${application.size()}
    ${application.isEmpty()}
    ${application.containsKey('foo')}
Note that you do not need to specify a namespace to access the request properties (as opposed to the request parameter) because all request properties are automatically added to the context root as variables:
    ${myRequestAttribute}

1.3 Web Context Objects

#request: Direct access to the object associated with the current request by javax.servlet.http.HttpServletRequest

    ${#request.getAttribute('foo')}
    ${#request.getParameter('foo')}
    ${#request.getContextPath()}
    ${#request.getRequestName()}

#session: Direct access to the object associated with the current request by javax.servlet.http.HttpSession

    ${#session.getAttribute('foo')}
    ${#session.id}
    ${#session.lastAccessedTime}

#servletContext: Direct access to the object associated with the current request for javax.servlet.ServletContext

    ${#servletContext.getAttribute('foo')}
    ${#servletContext.contextPath}

2. Expression Utility Object

Reference from Thymeleaf 3.0 Official Document Article 19

2.1 Execution Information

#execInfo: Expression object that provides useful information about the template being processed in the Thymeleaf standard expression

    ${#execInfo.templateName}
    ${#execInfo.templateMode}

    ${#execInfo.processedTemplateName}
    ${#execInfo.processedTemplateMode}

    ${#execInfo.templateNames}
    ${#execInfo.templateModes}

    ${#execInfo.templateStack}

2.2 Message Content

#messages: A utility method for getting externalized messages within variable expressions in the same way that messages are obtained using the #{...} syntax

    ${#messages.msg('msgKey')}
    ${#messages.msg('msgKey', param1)}
    ${#messages.msg('msgKey', param1, param2)}
    ${#messages.msg('msgKey', param1, param2, param3)}
    ${#messages.msgWithParams('msgKey', new Object[] {param1, param2, param3, param4})}
    ${#messages.arrayMsg(messageKeyArray)}
    ${#messages.listMsg(messageKeyList)}
    ${#messages.setMsg(messageKeySet)}

    ${#messages.msgOrNull('msgKey')}
    ${#messages.msgOrNull('msgKey', param1)}
    ${#messages.msgOrNull('msgKey', param1, param2)}
    ${#messages.msgOrNull('msgKey', param1, param2, param3)}
    ${#messages.msgOrNullWithParams('msgKey', new Object[] {param1, param2, param3, param4})}
    ${#messages.arrayMsgOrNull(messageKeyArray)}
    ${#messages.listMsgOrNull(messageKeyList)}
    ${#messages.setMsgOrNull(messageKeySet)}

2.3 URI / URL

#uris: Utility object (especially URI/URL) that performs URI/URL operations within a Thymeleaf standard expression

    // Escape/Unescape as a URI/URL path
    ${#uris.escapePath(uri)}
    ${#uris.escapePath(uri, encoding)}
    ${#uris.unescapePath(uri)}
    ${#uris.unescapePath(uri, encoding)}

    // Escape/Unescape as a URI/URL path segment (between '/' symbols)
    ${#uris.escapePathSegment(uri)}
    ${#uris.escapePathSegment(uri, encoding)}
    ${#uris.unescapePathSegment(uri)}
    ${#uris.unescapePathSegment(uri, encoding)}

    // Escape/Unescape as a Fragment Identifier (#frag)
    ${#uris.escapeFragmentId(uri)}
    ${#uris.escapeFragmentId(uri, encoding)}
    ${#uris.unescapeFragmentId(uri)}
    ${#uris.unescapeFragmentId(uri, encoding)}

    // Escape/Unescape as a Query Parameter (?var=value)
    ${#uris.escapeQueryParam(uri)}
    ${#uris.escapeQueryParam(uri, encoding)}
    ${#uris.unescapeQueryParam(uri)}
    ${#uris.unescapeQueryParam(uri, encoding)}

2.4 Conversion

#conversions: Utility object that allows conversion services to be performed anywhere in the template

    ${#conversions.convert(object, 'java.util.TimeZone')}
    ${#conversions.convert(object, targetClass)}

2.5 Date

#dates: Utility method for java.util.Date object

    ${#dates.format(date)}
    ${#dates.arrayFormat(datesArray)}
    ${#dates.listFormat(datesList)}
    ${#dates.setFormat(datesSet)}

    ${#dates.formatISO(date)}
    ${#dates.arrayFormatISO(datesArray)}
    ${#dates.listFormatISO(datesList)}
    ${#dates.setFormatISO(datesSet)}

    ${#dates.format(date, 'dd/MMM/yyyy HH:mm')}
    ${#dates.arrayFormat(datesArray, 'dd/MMM/yyyy HH:mm')}
    ${#dates.listFormat(datesList, 'dd/MMM/yyyy HH:mm')}
    ${#dates.setFormat(datesSet, 'dd/MMM/yyyy HH:mm')}

    ${#dates.day(date)}                    // also arrayDay(...), listDay(...), etc.
    ${#dates.month(date)}                  // also arrayMonth(...), listMonth(...), etc.
    ${#dates.monthName(date)}              // also arrayMonthName(...), listMonthName(...), etc.
    ${#dates.monthNameShort(date)}         // also arrayMonthNameShort(...), listMonthNameShort(...), etc.
    ${#dates.year(date)}                   // also arrayYear(...), listYear(...), etc.
    ${#dates.dayOfWeek(date)}              // also arrayDayOfWeek(...), listDayOfWeek(...), etc.
    ${#dates.dayOfWeekName(date)}          // also arrayDayOfWeekName(...), listDayOfWeekName(...), etc.
    ${#dates.dayOfWeekNameShort(date)}     // also arrayDayOfWeekNameShort(...), listDayOfWeekNameShort(...), etc.
    ${#dates.hour(date)}                   // also arrayHour(...), listHour(...), etc.
    ${#dates.minute(date)}                 // also arrayMinute(...), listMinute(...), etc.
    ${#dates.second(date)}                 // also arraySecond(...), listSecond(...), etc.
    ${#dates.millisecond(date)}            // also arrayMillisecond(...), listMillisecond(...), etc.

    ${#dates.create(year,month,day)}
    ${#dates.create(year,month,day,hour,minute)}
    ${#dates.create(year,month,day,hour,minute,second)}
    ${#dates.create(year,month,day,hour,minute,second,millisecond)}

    ${#dates.createNow()}
    ${#dates.createNowForTimeZone()}
    ${#dates.createToday()}
    ${#dates.createTodayForTimeZone()}

2.5 calendar

#calendars: similar to #dates, but for java.util.Calendar objects

    ${#calendars.format(cal)}
    ${#calendars.arrayFormat(calArray)}
    ${#calendars.listFormat(calList)}
    ${#calendars.setFormat(calSet)}

    ${#calendars.formatISO(cal)}
    ${#calendars.arrayFormatISO(calArray)}
    ${#calendars.listFormatISO(calList)}
    ${#calendars.setFormatISO(calSet)}

    ${#calendars.format(cal, 'dd/MMM/yyyy HH:mm')}
    ${#calendars.arrayFormat(calArray, 'dd/MMM/yyyy HH:mm')}
    ${#calendars.listFormat(calList, 'dd/MMM/yyyy HH:mm')}
    ${#calendars.setFormat(calSet, 'dd/MMM/yyyy HH:mm')}

    ${#calendars.day(date)}                // also arrayDay(...), listDay(...), etc.
    ${#calendars.month(date)}              // also arrayMonth(...), listMonth(...), etc.
    ${#calendars.monthName(date)}          // also arrayMonthName(...), listMonthName(...), etc.
    ${#calendars.monthNameShort(date)}     // also arrayMonthNameShort(...), listMonthNameShort(...), etc.
    ${#calendars.year(date)}               // also arrayYear(...), listYear(...), etc.
    ${#calendars.dayOfWeek(date)}          // also arrayDayOfWeek(...), listDayOfWeek(...), etc.
    ${#calendars.dayOfWeekName(date)}      // also arrayDayOfWeekName(...), listDayOfWeekName(...), etc.
    ${#calendars.dayOfWeekNameShort(date)} // also arrayDayOfWeekNameShort(...), listDayOfWeekNameShort(...), etc.
    ${#calendars.hour(date)}               // also arrayHour(...), listHour(...), etc.
    ${#calendars.minute(date)}             // also arrayMinute(...), listMinute(...), etc.
    ${#calendars.second(date)}             // also arraySecond(...), listSecond(...), etc.
    ${#calendars.millisecond(date)}        // also arrayMillisecond(...), listMillisecond(...), etc.

    ${#calendars.create(year,month,day)}
    ${#calendars.create(year,month,day,hour,minute)}
    ${#calendars.create(year,month,day,hour,minute,second)}
    ${#calendars.create(year,month,day,hour,minute,second,millisecond)}

    ${#calendars.createForTimeZone(year,month,day,timeZone)}
    ${#calendars.createForTimeZone(year,month,day,hour,minute,timeZone)}
    ${#calendars.createForTimeZone(year,month,day,hour,minute,second,timeZone)}
    ${#calendars.createForTimeZone(year,month,day,hour,minute,second,millisecond,timeZone)}

    ${#calendars.createNow()}
    ${#calendars.createNowForTimeZone()}
    ${#calendars.createToday()}
    ${#calendars.createTodayForTimeZone()}

2.5 digits

#numbers: A practical method for numeric objects

    ${#numbers.formatInteger(num,3)}
    ${#numbers.arrayFormatInteger(numArray,3)}
    ${#numbers.listFormatInteger(numList,3)}
    ${#numbers.setFormatInteger(numSet,3)}

    ${#numbers.formatInteger(num,3,'POINT')}
    ${#numbers.arrayFormatInteger(numArray,3,'POINT')}
    ${#numbers.listFormatInteger(numList,3,'POINT')}
    ${#numbers.setFormatInteger(numSet,3,'POINT')}

    ${#numbers.formatDecimal(num,3,2)}
    ${#numbers.arrayFormatDecimal(numArray,3,2)}
    ${#numbers.listFormatDecimal(numList,3,2)}
    ${#numbers.setFormatDecimal(numSet,3,2)}

    ${#numbers.formatDecimal(num,3,2,'COMMA')}
    ${#numbers.arrayFormatDecimal(numArray,3,2,'COMMA')}
    ${#numbers.listFormatDecimal(numList,3,2,'COMMA')}
    ${#numbers.setFormatDecimal(numSet,3,2,'COMMA')}

    ${#numbers.formatDecimal(num,3,'POINT',2,'COMMA')}
    ${#numbers.arrayFormatDecimal(numArray,3,'POINT',2,'COMMA')}
    ${#numbers.listFormatDecimal(numList,3,'POINT',2,'COMMA')}
    ${#numbers.setFormatDecimal(numSet,3,'POINT',2,'COMMA')}

    ${#numbers.formatCurrency(num)}
    ${#numbers.arrayFormatCurrency(numArray)}
    ${#numbers.listFormatCurrency(numList)}
    ${#numbers.setFormatCurrency(numSet)}

    ${#numbers.formatPercent(num)}
    ${#numbers.arrayFormatPercent(numArray)}
    ${#numbers.listFormatPercent(numList)}
    ${#numbers.setFormatPercent(numSet)}

    ${#numbers.formatPercent(num, 3, 2)}
    ${#numbers.arrayFormatPercent(numArray, 3, 2)}
    ${#numbers.listFormatPercent(numList, 3, 2)}
    ${#numbers.setFormatPercent(numSet, 3, 2)}

    ${#numbers.sequence(from,to)}
    ${#numbers.sequence(from,to,step)}

2.6 String

#strings:Practical methods for String objects

    ${#strings.toString(obj)}                           // also array*, list* and set*

    ${#strings.isEmpty(name)}
    ${#strings.arrayIsEmpty(nameArr)}
    ${#strings.listIsEmpty(nameList)}
    ${#strings.setIsEmpty(nameSet)}

    ${#strings.defaultString(text,default)}
    ${#strings.arrayDefaultString(textArr,default)}
    ${#strings.listDefaultString(textList,default)}
    ${#strings.setDefaultString(textSet,default)}

    ${#strings.contains(name,'ez')}                     // also array*, list* and set*
    ${#strings.containsIgnoreCase(name,'ez')}           // also array*, list* and set*

    ${#strings.startsWith(name,'Don')}                  // also array*, list* and set*
    ${#strings.endsWith(name,endingFragment)}           // also array*, list* and set*

    ${#strings.indexOf(name,frag)}                      // also array*, list* and set*
    ${#strings.substring(name,3,5)}                     // also array*, list* and set*
    ${#strings.substringAfter(name,prefix)}             // also array*, list* and set*
    ${#strings.substringBefore(name,suffix)}            // also array*, list* and set*
    ${#strings.replace(name,'las','ler')}               // also array*, list* and set*

    ${#strings.prepend(str,prefix)}                     // also array*, list* and set*
    ${#strings.append(str,suffix)}                      // also array*, list* and set*

    ${#strings.toUpperCase(name)}                       // also array*, list* and set*
    ${#strings.toLowerCase(name)}                       // also array*, list* and set*

    ${#strings.arrayJoin(namesArray,',')}
    ${#strings.listJoin(namesList,',')}
    ${#strings.setJoin(namesSet,',')}
    ${#strings.arraySplit(namesStr,',')}                // returns String[]
    ${#strings.listSplit(namesStr,',')}                 // returns List<String>
    ${#strings.setSplit(namesStr,',')}                  // returns Set<String>

    ${#strings.trim(str)}                               // also array*, list* and set*

    ${#strings.length(str)}                             // also array*, list* and set*

    ${#strings.abbreviate(str,10)}                      // also array*, list* and set*

    ${#strings.capitalize(str)}                         // also array*, list* and set*
    ${#strings.unCapitalize(str)}                       // also array*, list* and set*

    ${#strings.capitalizeWords(str)}                    // also array*, list* and set*
    ${#strings.capitalizeWords(str,delimiters)}         // also array*, list* and set*

    ${#strings.escapeXml(str)}                          // also array*, list* and set*
    ${#strings.escapeJava(str)}                         // also array*, list* and set*
    ${#strings.escapeJavaScript(str)}                   // also array*, list* and set*
    ${#strings.unescapeJava(str)}                       // also array*, list* and set*
    ${#strings.unescapeJavaScript(str)}                 // also array*, list* and set*

    ${#strings.equals(first, second)}
    ${#strings.equalsIgnoreCase(first, second)}
    ${#strings.concat(values...)}
    ${#strings.concatReplaceNulls(nullValue, values...)}

    ${#strings.randomAlphanumeric(count)}

2.7 Objects

#objects: A practical method for general objects

    ${#objects.nullSafe(obj,default)}
    ${#objects.arrayNullSafe(objArray,default)}
    ${#objects.listNullSafe(objList,default)}
    ${#objects.setNullSafe(objSet,default)}

2.8 Boolean

#bools: A practical method for Boolean value evaluation

    ${#bools.isTrue(obj)}
    ${#bools.arrayIsTrue(objArray)}
    ${#bools.listIsTrue(objList)}
    ${#bools.setIsTrue(objSet)}

    ${#bools.isFalse(cond)}
    ${#bools.arrayIsFalse(condArray)}
    ${#bools.listIsFalse(condList)}
    ${#bools.setIsFalse(condSet)}

    ${#bools.arrayAnd(condArray)}
    ${#bools.listAnd(condList)}
    ${#bools.setAnd(condSet)}

    ${#bools.arrayOr(condArray)}
    ${#bools.listOr(condList)}
    ${#bools.setOr(condSet)}

2.9 Arrays Array

#arrays: A practical method of arrays

    ${#arrays.toArray(object)}
    ${#arrays.toStringArray(object)}
    ${#arrays.toIntegerArray(object)}
    ${#arrays.toLongArray(object)}
    ${#arrays.toDoubleArray(object)}
    ${#arrays.toFloatArray(object)}
    ${#arrays.toBooleanArray(object)}
    ${#arrays.length(array)}
    ${#arrays.isEmpty(array)}
    ${#arrays.contains(array, element)}
    ${#arrays.containsAll(array, elements)}

2.10 List Collection

Practical methods for #lists:list collection

    ${#lists.toList(object)}
    ${#lists.size(list)}
    ${#lists.isEmpty(list)}
    ${#lists.contains(list, element)}
    ${#lists.containsAll(list, elements)}
    ${#lists.sort(list)}
    ${#lists.sort(list, comparator)}

2.11 Set Collection

#sets:Practical methods for set collection

${#sets.toSet(object)}

${#sets.size(set)}
${#sets.isEmpty(set)}

${#sets.contains(set, element)}
${#sets.containsAll(set, elements)}

2.12 Map Collection

Practical Methods for #maps:map Collection

${#maps.size(map)}

${#maps.isEmpty(map)}

${#maps.containsKey(map, key)}
${#maps.containsAllKeys(map, keys)}
${#maps.containsValue(map, value)}
${#maps.containsAllValues(map, value)}

2.13 Aggregates

#aggregates: A utility method for creating aggregates on arrays or collections

${#aggregates.sum(array)}
${#aggregates.sum(collection)}

${#aggregates.avg(array)}
${#aggregates.avg(collection)}

2.14 Number

#ids: A utility method for handling potentially duplicated id attributes (for example, as a result of an iteration)

${#ids.seq('someId')}

${#ids.next('someId')}
${#ids.prev('someId')}

Tags: Web Development Session encoding Thymeleaf Java

Posted on Wed, 06 May 2020 13:32:15 -0400 by umguy