Creating an object in a speed template

I have already addressed this issue, but it talks about the speed of liferay and seems to have access to this "$ portal" object, which I do not have access to.

Create an object in a speed template

In particular, I am trying to create a Locale object inside a template to pass it to a call to $ dateTool.format to get the result in a specific language.

I cannot create a local object and pass it to the template in advance, because this code can call many templates, each of which can be in different languages.

I tried

#set($localeClass = $portal.getClass().forName("java.util.Locale"))
$localeClass.getName

but it just prints out '$ localeClass.getName' (I was not sure if there was any magic predefined variable in $ portal or something else).

I also tried

#set($localeClass = java.util.Locale.class)
$localeClass.getName

but this gave me an exception at runtime when I tried to process the template.

ClassTool, Velocity, . , - $classTool.inspect("java.util.Locale").getType.getConstructor([$classTool.inspect("java.util.String"),$classTool.inspect("java.util.String")]).newInstance(["es","ES"]).

, , - .

, ConversionTool ( GenericTool), toLocale, .

$dateTool.format('dd-MMM-yyyy', $date, $conversionTool.toLocale("es_ES"))

, .

+5
2

, $localeClass.getName() $localeClass.name $localeClass.getName. . Velocity.

:

#set($localeClass = $portal.getClass().forName("java.util.Locale"))
$localeClass.getName()

"java.util.Locale" .

+1

,

$localeUtil.fromLanguageId("es_ES")

Velocity.

, , . , .

0

All Articles