I want to compare two strings to decide whether the first string is 'smaller' than the second string.
<#if name1 <= name2>
....
</#if>
Error:
Can't use operator "<=" on string values.
Can this be done in FreeMarker? Is it possible to call the String.compareTo
method in a template?
string (when used with a boolean value)Converts a boolean to a string. You can use it in two ways: As foo? string("yes", "no") : Formats the boolean value to the first parameter (here: "yes" ) if the boolean is true, and to the second parameter (here: "no" ) if it's false.
The FreeMarker template language doesn't know the Java language null at all. It doesn't have null keyword, and it can't test if something is null or not.
c (when used with numerical value) This built-in converts a number to string for a "computer language" as opposed to for human audience. That is, it formats with the rules that programming languages used to use, which is independent of all the locale and number format settings of FreeMarker.
If you meant length, you can use the length
built-in, for example:
<#if string?length gt 0>
If you mean to use a custom comparison and you are using Struts2, you can simply invoke an action method for it, let's assume you have a compare method:
public boolean compare(String str1, String str2) { ... }
then you can do this:
<#if action.compare(str1, str2) gt 0>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With