th:field gives error at testing

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

th:field gives error at testing

Michielb
Hi, I have a Thymeleaf page that works correctly, it is a form to create a new user. Now I try to test it, but it gives a error at the first input field. The problem is somehow with th:field="*{username}" (line 60), because when I remove all the th:fields, the test will continue. Am I doing somthing wrong? Or is there a other way to create form field that will pass the test?

test:

%CONTEXT
userObject = new [...].User()

# ------------------------------------------
%INPUT 
<span layout:include="page :: content" th:remove="tag"></span>

%INPUT[page] (file:src/main/webapp/WEB-INF/spring/views/CreateNewUser.html)


Parts of the layout:

<form th:if="${success == null || success == false}" action="#"
			th:action="@{/spring/CreateNewUser}"
			th:object="${userObject}" method="post">

[...]

						<td><input type="text" th:field="*{username}"
							th:class="logon" data-validation="length" 
							data-validation-length="6-50" />  
							 &nbsp;*&nbsp;
							 </td>


The error is:

09:51:21       |  ERROR [TemplateEngine] [THYMELEAF][main] Exception processing template "C:\[..]\test-classes\thymeleaftest\CreateNewUser.thtest-001": Error during execution of processor 'org.thymeleaf.spring4.processor.attr.SpringInputGeneralFieldAttrProcessor' (page:60)
[2014-07-21 09:51:21][RTJ8C0][main] [test:end][C:\[...]\target\test-classes\thymeleaftest\CreateNewUser.thtest-001][529208814][KO] Test FAILED: Error during execution of processor 'org.thymeleaf.spring4.processor.attr.SpringInputGeneralFieldAttrProcessor' (page:60) Time: 529208814ns (529ms).
org.thymeleaf.exceptions.TemplateProcessingException: Error during execution of processor 'org.thymeleaf.spring4.processor.attr.SpringInputGeneralFieldAttrProcessor' (page:60)
Reply | Threaded
Open this post in threaded view
|

Re: th:field gives error at testing

danielfernandez
Administrator
Unfortunately, your exception trace does not give much information... normally, an error there (it's the th:field itself what is breaking) means a Spring form binding issue... don't you obtain a more specific message?

Your code looks OK to me, as long as your "User" class has "getUsername()" and "setUsername()" methods (mind the lowercase "n"). You can see here an example of a working test with th:field (note the form backing bean is defined in the extended test file): https://github.com/thymeleaf/thymeleaf-tests/blob/b05d704199515127b388a366ce7778839b35c6f7/src/test-21-spring4/resources/engine21spring4/requestdata/formwith/formwith01.thtest