Search code examples
javajspspring-mvcspring-el

How to use SPEL eval @environment.getProperty(String string, Class<T> targetType) in JSP?


How to use SPEL eval

@environment.getProperty(String string, Class<T> targetType) 

in JSP?

I have a .property file with following entry,

app.conf.context.is_this_ok=true

I was able to get this working in JSP, with string valued varibale.

    <spring:eval var="isThisOk"
 expression="@environment.getProperty('app.conf.context.is_this_ok')"/>

But failed with getting value as boolean with following,

    <spring:eval var="isThisOk" expression="
           @environment.getProperty('app.conf.context.is_this_ok', 
                <%= java.lang.Boolean.class %>)"
    />

Please do suggest a way.


Solution

  • Try

    <spring:eval var="isThisOk" expression="
        @environment.getProperty('app.conf.context.is_this_ok', T(java.lang.Boolean))"
    />
    

    This is Spring EL syntax for accessing types.