#messages.msgOrNull returns ??message_en?? and not null

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

#messages.msgOrNull returns ??message_en?? and not null

Lt. Templeton Peck
Hi

The following test fails, shouldn't it return null and not ??field.message_en??

%INPUT
<!DOCTYPE html>
<html>
    <body>
        <p th:text="${#messages.msgOrNull('message')}"></p>
    </body>
</html>
# ------------------------------------------
%OUTPUT 
<!DOCTYPE html>
<html>
    <body>
        <p></p>
    </body>
</html>
Reply | Threaded
Open this post in threaded view
|

Re: #messages.msgOrNull returns ??message_en?? and not null

Emanuel
Administrator
Yeah, I would expect it to return null...

I just did the test and can confirm the same result.  Looks like the message resolver in the Thymeleaf Testing framework isn't returning null in this case.

Thanks for telling us about this bug!

---
GitHub issue: https://github.com/thymeleaf/thymeleaf-testing/issues/9
Reply | Threaded
Open this post in threaded view
|

Re: #messages.msgOrNull returns ??message_en?? and not null

Michielb
In reply to this post by Lt. Templeton Peck
My output is:


Obtained:
[  <body>
        <p>??message_en??</p>
    </body>
</h]
at line 5 col 12, but expected:
[  <body>
        <p></p>
    </body>
</html>] Time: 438686169ns (438ms).

What are your Context parameters? And I think you can better use th:if for this purpose
Reply | Threaded
Open this post in threaded view
|

Re: #messages.msgOrNull returns ??message_en?? and not null

Lt. Templeton Peck
Context:
    <bean id="templateResolver" class="org.thymeleaf.templateresolver.ServletContextTemplateResolver">
        <property name="templateMode" value="HTML5"/>
    </bean>

    <bean id="templateEngine" class="org.thymeleaf.spring4.SpringTemplateEngine">
        <property name="templateResolver" ref="templateResolver"/>
    </bean>

and using SpringStandardDialect & LayoutDialect

Currently using:
    th:unless="${#strings.startsWith(message, '??')}"
but would prefer native msgOrNull method.
Reply | Threaded
Open this post in threaded view
|

Re: #messages.msgOrNull returns ??message_en?? and not null

danielfernandez
Administrator
Adding link to GitHub issue for reference: https://github.com/thymeleaf/thymeleaf-testing/issues/9