Split a message value on space ?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Split a message value on space ?

Jan Goyvaerts
I've got a message named:

#{system.jvm.args}

Which are basically the JVM settings (ie -Xmx & co). This is a space separated list. So I thought the following markup would split and put each argument on a separate line:

<p th:each="arg : ${#strings.listSplit(#{system.jvm.args},' ')}" th:text="${arg}"/>

But it doesn't. It gives a syntax error. Any way I could get around this ?

TIA !

Jan


Caused by: org.springframework.expression.spel.SpelParseException: EL1043E:(pos 20): Unexpected token.  Expected 'identifier' but was 'lcurly({)'
        at org.springframework.expression.spel.standard.InternalSpelExpressionParser.raiseInternalException(InternalSpelExpressionParser.java:832)
        at org.springframework.expression.spel.standard.InternalSpelExpressionParser.eatToken(InternalSpelExpressionParser.java:755)
        at org.springframework.expression.spel.standard.InternalSpelExpressionParser.maybeEatFunctionOrVar(InternalSpelExpressionParser.java:355)
        at org.springframework.expression.spel.standard.InternalSpelExpressionParser.eatStartNode(InternalSpelExpressionParser.java:433)
        at org.springframework.expression.spel.standard.InternalSpelExpressionParser.eatPrimaryExpression(InternalSpelExpressionParser.java:282)
        at org.springframework.expression.spel.standard.InternalSpelExpressionParser.eatUnaryExpression(InternalSpelExpressionParser.java:275)
        at org.springframework.expression.spel.standard.InternalSpelExpressionParser.eatPowerIncDecExpression(InternalSpelExpressionParser.java:236)
        at org.springframework.expression.spel.standard.InternalSpelExpressionParser.eatProductExpression(InternalSpelExpressionParser.java:217)
Reply | Threaded
Open this post in threaded view
|

Re: Split a message value on space ?

Emanuel
Administrator
Maybe try the standard String.split() method?

<p th:each="arg: ${#{system.jvm.args}.split(' ')}" th:text="${arg}"/>
Reply | Threaded
Open this post in threaded view
|

Re: Split a message value on space ?

danielfernandez
Administrator
In reply to this post by Jan Goyvaerts
Hi,

You cannot use
#{system.jvm.args}
 inside a
${...}
 expression, because #{...} are not understood by OGNL or Spring EL (they are thymeleaf-specific).

For this reason, there is a utility object called "#messages", so that you can do:

<p th:each="arg : ${#strings.listSplit(#messages.msg('system.jvm.args'),' ')}" th:text="${arg}"/>

Regards,
Daniel.
Reply | Threaded
Open this post in threaded view
|

Re: Split a message value on space ?

Jan Goyvaerts
That did it !

Thanks a lot for all the speedy replies :-)