I´m studying Spring MVC with Tiles 3, JPA and all other cool stuff. I created a form to send data, below is the form:
<form:form method="POST" action="/users/save" enctype="multipart/form-data" modelAttribute="formUsuario">
<form:label path="username" for="username">Username</form:label>
<form:input type="text" id="username" path="username" class="span4" value="${user.username}" />
<form:label path="firstName" for="firstName">First name</form:label>
<form:input type="text" id="firstName" path="firstName" class="span4" value="${user.firstName}" />
</form:form>
The method inside the controller to add a new record:
@Secured("ROLE_USER")
@RequestMapping(value = "/new", method = RequestMethod.GET)
public String getNew(@ModelAttribute("formUsuario") br.com.rodrigoferra.domain.User user) {
logger.info("Add new user");
return "users/edit";
}
The method to save the new record:
@Secured("ROLE_USER")
@RequestMapping(value = "/save", method = RequestMethod.POST)
public @ResponseBody String doSave(@ModelAttribute("formUsuario") br.com.rodrigoferra.domain.User user, BindingResult results, Model model) {
if(results.hasErrors()) {
return "users/edit";
}
user = userRepository.save(user);
logger.info("Username: " + user.getUsername());
return "redirect:/users/";
}
It is saving the record, but it is saving everything as Null! The data from the form is being received by the controller. I searched a lot and found the same examples as this, but I can't get mine to work!
Is there any configuration I've missed?
Thanks and sorry for my bad english.
Edited:
Users bean:
@Entity(name="users")
public class User implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue( strategy = GenerationType.IDENTITY)
private Long id;
private String firstName;
private String lastName;
@Column(unique=true)
private String username;
private String password;
@Transient
private String passwordConfirmation;
private Date birthdate;
private String signature;
private String email;
private String sex;
private int active;