Search code examples
spring-bootthymeleaftextarea

Default values in input fields versus text areas in thymeleaf (spring boot)


I want to display default values in my input fields, so I followed answers in this stack overflow question (basically replacing th:field with th:value). Nevertheless when I tried to use the same strategy with textarea, it did not work. Why not? How do I achieve the same effect with a textarea?


Solution

  • <textarea /> doesn't have a value attribute. Use th:text instead.

    Alternatively, you could switch to th:field which will work the same for both <input /> and <textarea />. (When you use ``th:field`, you set the default value by setting correct property on your object rather than setting it in the HTML.)