0

I have a thymeleaf form and I would like to return a NULL value to my underlying controller instead of a blank String. Is there a way to do this directly in thymeleaf or do we have to set that conversion logic in the controller?

<div class="form-group">
                        <label for="note" class="formFieldTitle">Note</label>
                        <textarea class="form-control" rows="4" id="note" placeholder="Note" th:field="*{note}"
                            th:classappend="${validated == true ? (#fields.hasErrors('note') ? 'is-invalid' : 'is-valid') : ''}"
                            th:attr="readonly=${#authorization.expression('!hasAuthority(''Edit Patients'')')}">
                        </textarea>
                        <label class="errorMessage" th:if="${#fields.hasErrors('note')}" th:errors="*{note}">Note Error</label>
                    </div>
Martin
  • 1,977
  • 5
  • 30
  • 67
  • Does this answer your question? [Using Thymeleaf when the value is null](https://stackoverflow.com/questions/20636456/using-thymeleaf-when-the-value-is-null) – Boris Treukhov Dec 23 '19 at 22:18
  • Are you asking about after you are submitting the form (on POST)? – riddle_me_this Dec 24 '19 at 00:12
  • correct, when submitting the form i would like the field to have a NULL value as opposed to an empty string. The form is bean-backed and the entity is provided directly to the controller, which is why i'm not sure how to direct thymeleaf to provide a NULL value in the case of a field left blank. – Martin Dec 24 '19 at 01:54

0 Answers0