cybertextron cybertextron - 1 month ago 5
Java Question

Using models from another package in forms in Spring boot - Java

In my

page I have the following form:

<div id="deployment">
<form action="#" th:action="@{/builds}" th:object="${build}" method="post">
<textarea rows="20" cols="150" th:field="*{configuration}">
<button class="btn btn-primary btn-cons" type="submit">Deploy</button>

is in the

import builds.Build;

public class BuildsController {

// @Autowired
// private BuildsRepository buildsRepository;
private final static Logger logger = Logger.getLogger(BuildsController.class);

* Add the builds url page
public String index(Model model) {
model.addAttribute("builds", new Build());
return "builds";

* @param object
* @return
public Build deploy(@ModelAttribute Build build) {"--------- Deploying build: %s --------", build));
return build;


while the
model is in the

@Document(collection = "builds")
public class Build {

@JsonSerialize(using = ToStringSerializer.class)
private String id;
private String date;

private String configuration;

public Build() {

public Build(String configuration) { = new ObjectId().toHexString();
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); = dateFormat.format(new Date());
this.configuration = configuration;

So I'm getting the following error:

[THYMELEAF][http-nio-8080-exec-1] Exception processing template "builds": Exception evaluating SpringEL expression: "" (builds:514)
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.thymeleaf.exceptions.TemplateProcessingException: Exception evaluating SpringEL expression: "" (builds:514)] with root cause
org.springframework.expression.spel.SpelEvaluationException: EL1008E:(pos 7): Property or field 'build' cannot be found on object of type 'builds.Build' - maybe not public?

How can I use the
model in the form, since
is in another package?


You should use build not builds, when adding an attribute in the GET method, because you use build here th:object="${build}", so Spring can't find it.

model.addAttribute("build", new Build());

This doc example may help.