Spring Boot, Thymeleaf, Error during execution of processor - spring-boot

I have this thymeleaf template and I cannot find a way to make it work. The thymeleaf template is coded to do a post form like this:
<form class="mx-auto" method="post" th:object="${provideForm}">
<div class="mb-3">
<label class="form-label">Paciente</label>
<select class="form-select" th:field="*{pet}" >
<option selected>Seleccione su Mascota</option>
<option th:each="i : ${p}" th:value="${i.index}" th:utext="${i}"></option>
</select>
</div>
<div class="mb-3">
<label class="form-label">Servicio</label>
<select class="form-select" aria-label="Default select example" th:field="*{service}" >
<option selected>Seleccione el Servicio</option>
<option th:each="i : ${s}" th:value="${i.index}" th:utext="${i}"></option>
</select>
</div>
<div class="mb-3">
<label class="form-label">Lugar</label>
<select class="form-select" aria-label="Default select example" th:field="*{veterinary}">
<option selected>Seleccione la Veterinaria</option>
<option th:each="i : ${v}" th:value="${i.index}" th:utext="${i}"></option>
</select>
</div>
<div class="mb-3">
<label class="form-label">Fecha</label>
<input type="date" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" th:field="*{date}">
</div>
<div class="mb-3">
<label class="form-label">Hora</label>
<select class="form-select" th:field="*{time}">
<option th:each="i : ${#numbers.sequence(0,6)}" th:value="${i}" th:text="'1' + ${i} + ':00:00'"></option>
</select>
</div>
<button type="submit" class="btn btn-primary">Agregar</button>
<button type="button" class="btn btn-outline-danger">Cancelar</button>
</form>
The spring boot is trying to pass the arrays like this:
#GetMapping(value="/appointmentsView")
public ModelAndView appointmentsView(){
if(!Objects.nonNull(authUser)){
return login();
}
updateInfo();
ModelAndView mv = new ModelAndView("appoitnmentsView");
List<String> displayPets = new ArrayList<String>();
for(Pet p : pets){
displayPets.add(p.getName());
}
mv.addObject("p", displayPets);
List<String> displayServices = new ArrayList<String>();
for(Services s : services){
displayServices.add(s.getService_name());
}
mv.addObject("s", displayServices);
List<String> displayVeterinaries = new ArrayList<String>();
for(Veterinary v : veterinaries){
displayVeterinaries.add(v.getVeterinary_name());
}
mv.addObject("v", displayVeterinaries);
return mv;
}
I am always getting a 500 error code:
org.thymeleaf.exceptions.TemplateProcessingException: Error during execution of processor 'org.thymeleaf.spring5.processor.SpringSelectFieldTagProcessor' (template: "appointmentsView" - line 38, col 47)
at org.thymeleaf.processor.element.AbstractAttributeTagProcessor.doProcess(AbstractAttributeTagProcessor.java:117) ~[thymeleaf-3.0.12.RELEASE.jar:3.0.12.RELEASE]
at org.thymeleaf.processor.element.AbstractElementTagProcessor.process(AbstractElementTagProcessor.java:95) ~[thymeleaf-3.0.12.RELEASE.jar:3.0.12.RELEASE]
The only way I could fix this problem is by moving the th:field that are on the select tags to the option tags. However, by doing that it always return null on the th:field

Related

Laravel Error during update - Undefined variable: id

I am working on a project using Laravel-5.8
protected $table = 'ratings';
protected $fillable = [
'rating_type',
'rating_value',
'rating_description',
];
public function rules()
{
return [
'rating_type' => 'required|numeric|min:1|max:10|unique:appraisal_ratings,rating_type,company_id'.$this->id,
];
}
The rating has an id column, and that's the primary key. Why I checked it against company_id is that different companies can have the same rating type.
Controller
public function edit($id)
{
$rating = Rating::where('id', $id)->first();
return view('ratings.edit')
->with('rating', $rating)
->with('rating_types', $this->rating_types)
->with('rating_descriptions', $this->rating_descriptions)
->with('rating_values', $this->rating_values);
}
public function update(UpdateRatingRequest $request, $id)
{
$rating = Rating::find($id);
$rating->rating_type = $request->rating_type;
$rating->rating_value = $request->rating_value;
$rating->rating_description = $request->rating_description;
$rating->save();
Session::flash('success', 'Rating is updated successfully');
return redirect()->route('ratings.index');
}
edit.blade
<form action="{{route('ratings.update', ['id'=>$rating->id])}}" method="post" class="form-horizontal" enctype="multipart/form-data">
{{ csrf_field() }}
<input name="_method" type="hidden" value="PUT">
<div class="card-body">
<div class="form-body">
<div class="row">
<div class="col-12 col-sm-4">
<div class="form-group">
<label class="control-label"> Rating:<span style="color:red;">*</span></label>
<select class="form-control select2bs4" data-placeholder="Choose Rating" tabindex="1" name="rating_type" style="width: 100%;">
<option value="">Select Rating</option>
#foreach($rating_types as $k => $rating_type)
<option value="{{$k}}" #if($rating->rating_type == $k) selected #endif>{{$rating_type}}</option>
#endforeach
</select>
</div>
</div>
<div class="col-12 col-sm-4">
<div class="form-group">
<label class="control-label"> Description:<span style="color:red;">*</span></label>
<select class="form-control select2bs4" data-placeholder="Choose Description" tabindex="1" name="rating_description" style="width: 100%;">
<option value="">Select Description</option>
#foreach($rating_descriptions as $k => $rating_description)
<option value="{{$k}}" #if($rating->rating_description == $k) selected #endif>{{$rating_description}}</option>
#endforeach
</select>
</div>
</div>
<div class="col-12 col-sm-4">
<div class="form-group">
<label class="control-label"> Rating Score:<span style="color:red;">*</span></label>
<select class="form-control select2bs4" data-placeholder="Choose Rating Score" tabindex="1" name="rating_value" style="width: 100%;">
<option value="">Select Rating Score</option>
#foreach($rating_values as $k => $rating_value)
<option value="{{$k}}" #if($rating->rating_value == $k) selected #endif>{{$rating_value}}</option>
#endforeach
</select>
</div>
</div>
</div>
</div>
</div>
<!-- /.card-body -->
<div class="card-footer">
<button type="submit" class="btn btn-primary">{{ trans('global.save') }}</button>
<button type="button" onclick="window.location.href='{{route('ratings.index')}}'" class="btn btn-default">Cancel</button>
</div>
</form>
When I clicked on the save button to update, I got this error:
rating_type already exists.
That error should not have occured since I am doing update.
How do I resolve it?
Thank you.
You are checking the unique on update wrong
Unique Rule Usage
unique:table,column,except,idColumn
* 3rd param is for value for column to except and 4th is for column to except
Fix
//App\Http\Requests\UpdateRatingRequest
'rating_type' => 'required|numeric|min:1|max:10|unique:table_name,rating_type,table_primary_key'.$this->id,

Thymeleaf dynamic form action does not work

I am loading the home.html page by setting the following model attributes:
#GetMapping("/")
private String getHomePage(Model model) {
model.addAttribute("allUsers", this.userService.findAll());
model.addAttribute("user", new User());
model.addAttribute("queryResult", "");
model.addAttribute("errors", new ArrayList<>());
return "home";
}
and here is my form for updating a user's data:
<form action="#" th:action="#{/user/{username}(username=${user.username})}" th:object="${user}" th:method="put">
<label for="username">Username</label>
<select th:field="*{username}" id="username">
<option th:each="singleUser : ${allUsers}" th:value="${singleUser.username}" th:text="${singleUser.username}"></option>
</select>
<label for="password">Password</label>
<input type="password" th:field="*{password}" id="password" >
<span th:if="${#fields.hasErrors('password')}" th:errors="*{password}"></span>
<label for="status">Status</label>
<select th:field="*{status}" id="status">
<option th:value="'Activated'" th:text="Activated"></option>
<option th:value="'Deactivated'" th:text="Deactivated"></option>
</select>
<button type="submit">UPDATE DATA</button>
</form>
When I try to submit this form, it does not bind the username to the URL.
instead of having /user/whateverUsername I have only /user.
I need to bind the value of this select element:
<select th:field="*{username}" id="username">
<option th:each="singleUser : ${allUsers}" th:value="${singleUser.username}" th:text="${singleUser.username}"></option>
</select>
How can I solve this problem?
Thank you very much!

multimple select2 with laravel vue js not working

i want to make dynamic form .so for that i tried foreach loop .everything going fine without select options. For making classname or id name unique i want place a index value but cant not place index value.take a look below:
<div class="form-group m-form__group row " v-for="(pack,index) in packs">
<div class="col-lg-3">
<label>SKU: #{{ index }}</label>
<input v-model="pack.sku" type="text" name="name" class="form-control m-input" placeholder="SKU">
</div>
<div class="col-lg-3">
<label>Unit:</label>
<select class="form-control select2 #{{ index }}" name="unit" v-model="pack.unit" >
<option value="0">KG</option>
<option value="1">ML</option>
<option value="2">Liter</option>
</select>
</div>
<div class="col-lg-3">
<label>Size:</label>
<input v-model="pack.size" type="number" name="name" class="form-control m-input" placeholder="Size">
</div>
<div class="col-lg-3">
<label>Barcode:</label>
<input v-model="pack.barcode" type="number" name="barcode" class="form-control m-input" placeholder="Barcode">
</div>
</div>
you need to reload select2.
html markup:
<select class="form-control select2 #{{ index }}" name="unit" v-model="pack.unit" id="unit">
<option value="0">KG</option>
<option value="1">ML</option>
<option value="2">Liter</option>
</select>
Vuejs code:
...
components: {
},
mounted() {
setTimeOut(() => {
let unit = $('#unit'); // or document.querySelector('#unit');
unit.select2();
}, 100);
},

How to do server side validation in spring mvc using validator class

Hi am new to spring mvc i have to do sever side validation using separate validator class. i have two model with one to many relation i have to register them before register them i am new server side validation in spring mvc to use spring form and all
<form id="studentEnrollmentForm" method="post" class="form-horizontal" action="saveStudentByAdmin">
<div class="form-group">
<label class="col-xs-2 control-label">Student Full Name</label>
<div class="group">
<div class="col-xs-3">
<input type="text" class="form-control" name="studentFirstName" id="fn" placeholder="First name" />
</div>
</div>
<div class="col-xs-3">
<input type="text" class="form-control" name="studentMiddleName" placeholder="Middle name" />
</div>
<div class="col-xs-3">
<input type="text" class="form-control" name="studentLastName" placeholder="Last name" />
</div>
</div>
<div class="form-group">
<label class="col-xs-2 control-label">Parents Full Name</label>
<div class="col-xs-3">
<input type="text" class="form-control" name="parentFirstName" placeholder="First name" />
</div>
<div class="col-xs-3">
<input type="text" class="form-control" name="parentMiddleName" placeholder="Middle name" />
</div>
<div class="col-xs-3">
<input type="text" class="form-control" name="parentLastName" placeholder="Last name" />
</div>
</div>
<div class="form-group">
<label class="col-xs-2 control-label">Date-of-birth</label>
<div class="col-xs-3 ">
<div class="input-group input-append date" id="studentDOB">
<input type="Text" class="form-control" name="studentDOB" /> <span
class="input-group-addon add-on"><span
class="glyphicon glyphicon-calendar"></span></span>
</div>
</div>
<label class="col-xs-3 control-label">Gender</label>
<div class="col-xs-3">
<div class="btn-group" data-toggle="buttons">
<label class="btn btn-default">
<input type="radio" name="studentGender" value="male" />Male</label>
<label class="btn btn-default">
<input type="radio" name="studentGender" value="female" />Female</label>
</div>
</div>
</div>
<div class="form-group">
<label class="col-xs-2 control-label">Phone</label>
<div class="col-xs-3">
<input type="text" class="form-control" name="parentPhoneNumber" placeholder="Phone number" />
</div>
<label class="col-xs-3 control-label">Email</label>
<div class="col-xs-3">
<input type="text" class="form-control" name="parentEmail" placeholder="Email" />
</div>
</div>
<div class="form-group">
<label class="col-xs-2 control-label">Permanent Address</label>
<div class="col-xs-3">
<textarea class="form-control" rows="3" name="studentPermanentAddress" /></textarea>
</div>
<label class="col-xs-3 control-label">Present Address</label>
<div class="col-xs-3">
<textarea class="form-control" rows="3" name="studentPresentAddress" /></textarea>
</div>
</div>
<div class="form-group">
<label class="col-xs-2 control-label">Class to join</label>
<div class="col-xs-3">
<!-- <input type="text" class="form-control" name="className" placeholder="Enter Class" /> -->
<select name="className" class="form-control">
<option value="">Select class </option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
</select>
</div>
</div>
<div class="form-group">
<div class="col-xs-1 ">
<button type="submit" class="btn btn-primary ">Submit</button>
</div>
<div class="col-xs-1 ">
<button type="reset" class="btn btn-default" id="rstbutton">Refresh</button>
</div>
</div>
</form>
Controller
#Controller
#RequestMapping("/")
public class AdminRegistrationController {
#Autowired
private IAdminRegistrationService adminRegistrationService;
#RequestMapping(value = "/register", method = RequestMethod.GET)
public String viewRegistrationPage(Model model) {
StudentDTO studentDTO = new StudentDTO();
ParentDTO pdto=new ParentDTO();
model.addAttribute("teacherDTO", studentDTO);
model.addAttribute("teacherDTO", pdto);
return "StudentEnrollmentByAdmin";
}
#RequestMapping(value = "/saveStudentByAdmin", method = RequestMethod.POST)
public String saveTeacherByAdmin(#ModelAttribute StudentDTO sdto,#ModelAttribute ParentDTO pdto) {
System.out.println(sdto.getStudentFirstName());
System.out.println(pdto.getParentFirstName());
return "redirect:/register"; // this line redirecting to above method to avoid same data insertion again when i press f5
//return "TeacherEnrollmentByAdmin"; To know duplication insertion comment above line and above method current this line
//when you get response page(after insertion of data) press f5 and see in data base
}
}
My Example validator class
#Component
public class StudentRegistrationFromAdminValidator implements Validator{
public boolean supports(Class<?> clazz) {
return StudentDTO.class.isAssignableFrom(clazz);
//return ParentDTO.class.isAssignableFrom(clazz);
}
public void validate(Object target, Errors errors) {
StudentDTO student = (StudentDTO)target;
ParentDTO parent = (ParentDTO)target;
String studentFirstName = student.getStudentFirstName();
String parentFirstName=parent.getParentFirstName();
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "studentFirstName", "student.studentFirstName.empty");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "parentFirstName", "parent.parentFirstName.empty");
if(studentFirstName.equals("pradee")){
errors.rejectValue("studentFirstName", "student.studentFirstName.invalid");
}
if(parentFirstName.equals("pradee")){
errors.rejectValue("parentFirstName", "parent.parentFirstName.invalid");
}
}
}
In StudentDTO and ParentDTO classes, you can give various validator annotations from javax.validation.constraints package and org.hibernate.validator.constraints package(if using hibernate).
public class StudentDTO {
#Size(min=6, max=12)
private String firstName;
#Size(min=6, max=12)
private String lastName;
//getter setter
}
Then add javax.validation.Valid annotation and
org.springframework.validation.BindingResult interface in controller method as follows.
#RequestMapping(value = "/saveStudentByAdmin", method = RequestMethod.POST)
public String saveTeacherByAdmin(#Valid #ModelAttribute StudentDTO sdto,#ModelAttribute ParentDTO pdto,
BindingResult bindingResult) {
if(bindingResult.hasErrors()) {
System.out.println(bindingResult.getAllErrors().get(0).getDefaultMessage());
}
}

Why the properties of a command object associate to a submitted form are null in this Spring MVC application?

I am pretty new in Spring MVC and I have the following problem trying to populate a command object submitting a form to a controller method.
So I have the following situation:
I have this command object class named Step2Form:
public class Step2Form {
String nome;
String cognome;
int giornoNascita;
int meseNascita;
int annoNascita;
String nazioneNascita;
String regioneNascita;
String provinciaNascita;
String comuneNascita;
String sesso;
String eMail;
String confermaEmail;
String trattamentoDatiPersonali;
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public String getCognome() {
return cognome;
}
public void setCognome(String cognome) {
this.cognome = cognome;
}
public int getGiornoNascita() {
return giornoNascita;
}
public void setGiornoNascita(int giornoNascita) {
this.giornoNascita = giornoNascita;
}
public int getMeseNascita() {
return meseNascita;
}
public void setMeseNascita(int meseNascita) {
this.meseNascita = meseNascita;
}
public int getAnnoNascita() {
return annoNascita;
}
public void setAnnoNascita(int annoNascita) {
this.annoNascita = annoNascita;
}
public String getNazioneNascita() {
return nazioneNascita;
}
public void setNazioneNascita(String nazioneNascita) {
this.nazioneNascita = nazioneNascita;
}
public String getRegioneNascita() {
return regioneNascita;
}
public void setRegioneNascita(String regioneNascita) {
this.regioneNascita = regioneNascita;
}
public String getProvinciaNascita() {
return provinciaNascita;
}
public void setProvinciaNascita(String provinciaNascita) {
this.provinciaNascita = provinciaNascita;
}
public String getComuneNascita() {
return comuneNascita;
}
public void setComuneNascita(String comuneNascita) {
this.comuneNascita = comuneNascita;
}
public String getSesso() {
return sesso;
}
public void setSesso(String sesso) {
this.sesso = sesso;
}
public String geteMail() {
return eMail;
}
public void seteMail(String eMail) {
this.eMail = eMail;
}
public String getConfermaEmail() {
return confermaEmail;
}
public void setConfermaEmail(String confermaEmail) {
this.confermaEmail = confermaEmail;
}
public String getTrattamentoDatiPersonali() {
return trattamentoDatiPersonali;
}
public void setTrattamentoDatiPersonali(String trattamentoDatiPersonali) {
this.trattamentoDatiPersonali = trattamentoDatiPersonali;
}
}
that maps this form into a view:
<form id="reg-form" name="reg-form" action="<#spring.url '/iscrizioneStep3' />" method="post">
<fieldset>
<div class="form-group">
<label for="name">Nome <span aria-hidden="true">*</span>:</label>
<input type="text" id="name" name="name" class="form-control input-mm" placeholder="Inserisci il tuo nome" data-validation="[NOTEMPTY]" data-validation-label="nome" aria-required="true" tabindex="10">
</div>
<div class="form-group">
<label for="surname">Cognome <span aria-hidden="true">*</span>:</label>
<input type="text" id="surname" name="surname" class="form-control input-mm" placeholder="Inserisci il tuo cognome" data-validation="[NOTEMPTY]" data-validation-label="cognome" aria-required="true" tabindex="20">
</div>
<div class="form-group grouped">
<label>Data di nascita <span aria-hidden="true">*</span>:</label>
<div class="row">
<div class="col-xs-3 col-md-4">
<select id="birth-day" name="birth-day" class="form-control selectpicker select-mm" title="Giorno" data-validation="[NOTEMPTY, INTEGER]" data-validation-label="giorno di nascita" aria-label="seleziona il giorno di nascita" aria-required="true" tabindex="30">
<option value="01">01</option>
<option value="02">02</option>
<option value="03">03</option>
</select>
</div>
<div class="col-xs-5 col-md-5">
<select id="birth-month" name="birth-month" class="form-control selectpicker select-mm" title="Mese" data-validation="[NOTEMPTY, INTEGER]" data-validation-label="mese di nascita" aria-label="seleziona il mese di nascita" aria-required="true" tabindex="40">
<option value="01">Gennaio</option>
<option value="02">Febbraio</option>
<option value="03">Marzo</option>
</select>
</div>
<div class="col-xs-4 col-md-3">
<select id="birth-year" name="birth-year" class="form-control selectpicker select-mm" title="Anno" data-validation="[NOTEMPTY, INTEGER]" data-validation-label="anno di nascita" aria-label="seleziona l'anno di nascita" aria-required="true" tabindex="50">
<option value="2000">2000</option>
<option value="1999">1999</option>
<option value="1998">1998</option>
</select>
</div>
</div>
</div>
<div class="form-group">
<label for="country">Nazione di nascita<span aria-hidden="true">*</span>:</label>
<select id="country" name="country" class="sel-dynamic sel-haschild form-control selectpicker select-mm" title="Seleziona la nazione" data-validation="[NOTEMPTY]" data-validation-label="nazione" aria-required="true" tabindex="60">
<option value="italy">Italia</option>
<option value="estero">Estero</option>
</select>
</div>
<div class="form-group">
<label for="region">Regione di nascita<span aria-hidden="true">*</span>:</label>
<select id="region" name="region" class="sel-dynamic sel-haschild form-control selectpicker select-mm" title="É necessario selezionare una regione..." data-validation="[NOTEMPTY]" data-validation-label="regione" data-choice="Seleziona la regione" aria-required="true" disabled tabindex="70">
<option disabled value="0"> </option>
</select>
</div>
<div class="form-group">
<label for="district">Provincia di nascita<span aria-hidden="true">*</span>:</label>
<select id="district" name="district" class="sel-dynamic sel-haschild form-control selectpicker select-mm" title="É necessario selezionare una provincia..." data-validation="[NOTEMPTY]" data-validation-label="provincia" data-choice="Seleziona la provincia" aria-required="true" disabled tabindex="80">
<option disabled value="0"> </option>
</select>
</div>
<div class="form-group clearfix">
<label for="municipality">Comune <span aria-hidden="true">*</span>: </label>
<select id="municipality" name="municipality" class="sel-dynamic form-control selectpicker select-mm" title="É necessario selezionare un comune..." data-validation="[NOTEMPTY]" data-validation-label="comune" data-choice="Seleziona un comune" aria-required="true" disabled tabindex="90">
<option disabled value="0"> </option>
</select>
</div>
<div class="form-group">
<label>Sesso <span aria-hidden="true">*</span>:</label>
<div class="genderbg clearfix">
<label id="label-gender-m" class="radio-inline pull-left">
<input id="gender-m" type="radio" name="gender" value="m" data-validation="[NOTEMPTY]" data-validation-label="sesso" aria-label="scelta sesso maschio" tabindex="100">Maschio
</label>
<label id="label-gender-f" class="radio-inline pull-right">
<input id="gender-f" type="radio" name="gender" value="f" aria-label="scelta sesso femmina" tabindex="110">Femmina
</label>
</div>
</div>
<div class="form-group">
<label for="email">Email <span aria-hidden="true">*</span>:</label>
<input type="text" id="email" name="email" class="form-control input-mm" placeholder="Esempio: nome#email.it" data-validation="[NOTEMPTY, EMAIL]" data-validation-label="email" aria-required="true" tabindex="120">
</div>
<div class="form-group">
<label for="email-confirm">Conferma Email <span aria-hidden="true">*</span>:</label>
<input type="text" id="email-confirm" name="email-confirm" class="form-control input-mm" data-validation="[NOTEMPTY, V==email]" data-validation-label="conferma email" aria-required="true" tabindex="130">
</div>
<div class="form-group">
<label>Termini e condizioni:</label>
<p class="small">Dichiaro di aver letto e di accettare le condizioni generali</p>
<label id="label-gencond" class="radio-inline">
<input id="gencond" type="radio" name="gencond" value="y" data-validation="[NOTEMPTY]" data-validation-label="termini e condizioni" tabindex="150"><strong>Accetto</strong>
</label>
</div>
<div class="form-group">
<label>Trattamento dei dati personali:</label>
<p class="small">I dati raccolti saranno utili a soddisfare le tue richieste, a migliorare i nostri servizi e a poterti comunicare le nostre novità.<br>
Leggi l' informativa sulla privacy e, se vuoi, presta il consenso.</p>
<label id="label-privacy-y" class="radio-inline">
<input id="privacy-y" type="radio" name="privacy" value="y" data-validation="[NOTEMPTY]" data-validation-label="privacy" tabindex="170"><strong>Accetto</strong>
</label>
<label id="label-privacy-n" class="radio-inline">
<input id="privacy-n" type="radio" name="privacy" value="n" tabindex="180"><strong>Non Accetto</strong>
</label>
</div>
<button type="submit" class="btn btn-block submit-btn" aria-label="prosegui la registrazione" tabindex="190">Passaggio 3</button>
</fieldset>
</form>
Finnally I have this controller method that handle the submit of the previous form:
#RequestMapping(value = "/iscrizioneStep3", method=RequestMethod.POST)
public String iscrizioneStep3(#ModelAttribute("SpringWeb")Step2Form step2Form, ModelMap model, HttpServletRequest request) {
System.out.println("INTO iscrizioneStep3()");
System.out.println("NOME: " + step2Form.getNome());
return "iscrizioneStep3";
}
When I submit the form it enter into the iscrizioneStep3() method but the problem is that when it go to perform:
System.out.println("NOME: " + step2Form.getNome());
this is what obtain in my Eclipse console:
19:39:00,874 INFO [stdout] (http-localhost/127.0.0.1:8080-1) NOME: null
So it have not setted the nome field of my command object.
Why? What is wrong? What am I missing? How can I fix this isue?
<input type="text" id="name" name="name" class="form-control input-mm" placeholder="Inserisci il tuo nome" data-validation="[NOTEMPTY]" data-validation-label="nome" aria-required="true" tabindex="10">
</div>
Should be
<input type="text" id="nome" name="nome" class="form-control input-mm" placeholder="Inserisci il tuo nome" data-validation="[NOTEMPTY]" data-validation-label="nome" aria-required="true" tabindex="10">
</div>
or am I missing something else here?
Basicly spring maps the fields by the "name" attribute to the appropriate variable in class (<input type="hidden" name="tester" /> should map to a variable named "tester".

Resources