How do I assign an object to a member class in JSP - spring

I am building a tour application. I have bookings which point to a tour modality but I haven't been able to assign the book modality when adding a new booking using JSLT.
Here's my JSP code:
<c:forEach items="${modalities}" var="modality">
<form:form method="POST" action="/book_tour" modelAttribute="booking">
<p>${modality.name}</p>
<jsp:setProperty name="booking" property="tourModality" value="${modality}"></jsp:setProperty>
<input name="modality" type="hidden" value="${modality}">
<div class="form-group">
<form:label path="calendarDate">Escoja una fecha</form:label>
<div class='input-group date' id='datetimepicker'>
<form:input path="calendarDate" type='text' class="form-control"/>
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
<div class="input-group">
<form:label path="calendarDate">Hora: </form:label>
<form:select path="calendarDate">
<c:forEach items="${modality.tourHours}" var="tourHour">
<option>${tourHour.timeSlot}</option>
</c:forEach>
</form:select>
</div>
</div>
<input type="submit" class="btn btn-success" value="Reservar"/>
</form:form>

Related

Spring MVC editable table (Thymeleaf)

I have 2 entities - Invoice and InvoiceProduct. Invoice class has a field List of InvoiceProduct because Invoice has #OneToMany mapping on InvoiceProduct.
I want to send the List of InvoiceProduct to Thymeleaf with with editable fields with a Submit button. When I click on Submit button, the new edited List should be returned to the controller. However, I am able to send the list to the view, but when I send the edited list to controller, it is being passed as 'null'.
update-invoice.html:
<form action="#" th:action="#{/api/invoice/saveInvoice}" th:object="${invoice}" method="POST">
<table class="table table-bordered table-striped">
<thead class="thead-dark">
<tr>
<th>PID</th>
<th>Quantity</th>
<th>Unit Price</th>
</tr>
</thead>
<tbody>
<tr th:each="temp : ${invoice?.invoiceProducts}" >
<td><input name="invoiceProducts[${tempStat.index}].productId" th:value="${temp.productId}"/></td>
<td><input name="invoiceProducts[${tempStat.index}].quantity" th:value="${temp.quantity}"/></td>
<td><input name="invoiceProducts[${tempStat.index}].price" th:value="${temp.price}"/></td>
</tr>
</tbody>
</table>
<button type="submit" class="btn btn-info col-2">Submit</button>
</form>
InvoiceController:
#PostMapping("/saveInvoice")
public String postInvoice(#ModelAttribute("invoice") Invoice invoice) {
logger.info("invoice products " + invoice.getInvoiceProducts());
return "dummy";
}
What else do I need to add so that my update-invoice.html passes the list to my controller ?
You can try something like below as an example for thymleaf:-
<form method="post" th:action="#{/users/}" th:object="${userInfo}" class="col card p-3 mb-5">
<div class="form-group">
<label for="firstName">First Name</label>
<input id="firstName" placeholder="Enter First Name" required type="text" th:field="*{firstName}"
class="form-control"/>
</div>
<div class="form-group">
<label for="lastName">Last Name</label>
<input id="lastName" placeholder="Enter Last Name" required type="text" th:field="*{lastName}"
class="form-control"/>
</div>
<div class="form-group">
<label for="role">Role</label>
<select id="role" required th:field="*{role}" class="form-control ">
<option value="" hidden>Select a role</option>
<option th:each="role : ${T(com.springhow.examples.springboot.thymeleaf.domain.entities.Role).values()}"
th:value="${role}"
th:text="${role}">
</option>
</select>
</div>
<input type="submit" class="btn btn-primary" value="Create User">
</form>
and into Controller:-
#RequestMapping(value = "/", method = RequestMethod.POST)
public String createUser(Model model, #ModelAttribute UserInfo userInfo) {
UserInfo user = userService.createUser(userInfo);
return "redirect:/users/";
}

How to pass data to a form in laravel 8

This is how I fill my data in a table body:
<tbody>
#foreach($ArrayProducts as $product)
<tr>
<td>{{$product['name']}}</td>
<td>{{$product['description']}}</td>
<td>{{$product['price']}}</td>
<td>{{$product['stock']}}</td>
<td><button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal">Edit</td>
</tr>
#endforeach
</tbody>
But how I can pass the object that is selected in the button Edit of the product to a form to update the product:
<form method="PUT" action="productos">
#csrf
<div class="form-group">
<label>Name</label>
<input type="text" class="form-control" id="nombre" name="name" required>
</div>
<div class="form-group">
<label >Descripcion</label>
<input type="text" class="form-control" id="description" name="description" required>
</div>
<div class="form-group">
<label>price</label>
<input id="price" type="number" class="form-control" name="price" required>
</div>
<div class="form-group">
<label>Stock</label>
<input id="stock" type="number" class="form-control" name="stock" required >
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">Save changes</button>
</div>
</form>
You will also want to modify this so you know the ID of the product you are editing and do error handling.
<tbody>
#foreach($ArrayProducts as $product)
<tr>
<td>{{$product['name']}}</td>
<td>{{$product['description']}}</td>
<td>{{$product['price']}}</td>
<td>{{$product['stock']}}</td>
<td><button type="button" class="btn btn-primary" data-toggle="modal" data-target="#product-model-{{ $product['id'] }}">Edit</button></td>
</tr>
#endforeach
</tbody>
#foreach($ArrayProducts as $product)
<div class="model" id="product-model-{{ $product['id'] }}">
<form method="PUT" action="productos">
#csrf
<div class="form-group">
<label>Name</label>
<input type="text" class="form-control" id="nombre" name="name" required value="{{ $product['name'] }}">
</div>
<div class="form-group">
<label >Descripcion</label>
<input type="text" class="form-control" id="description" name="description" required value="{{ $product['description'] }}">
</div>
<div class="form-group">
<label>price</label>
<input id="price" type="number" class="form-control" name="price" required value="{{ $product['price'] }}">
</div>
<div class="form-group">
<label>Stock</label>
<input id="stock" type="number" class="form-control" name="stock" required value="{{ $product['stock'] }}">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">Save changes</button>
</div>
</form>
</div>
#endforeach

Button can't save first item when clicked

In a foreach loop, I have more than one item and each item has a button called "save". However, when I click on the first "save" button, it saves only the last item in my database.
#foreach($product_dr as $product)
<tr>
<td style="font-size: 20px;color: #101010">
<div class="form-group">
<input type="hidden" name="title" value="{{$product->title}}">
<label for="inputText3" class="col-form-label"></label>
{{$product->title}}
</div>
</td>
<td style="font-size: 20px;color: #2ec551">
<div class="form-group">
<input id="inputText4" VALUE="{{$product->price}}" type="text" name="price" class="form-control" placeholder="Amount" style="width: 100px">
</div>
</td>
<td style="font-size: 20px;color: #2ec551">
<div class="form-group">
<input id="inputText4" VALUE="1" type="number" name="amount" class="form-control" placeholder="Amount" style="width: 100px">
</div>
</td>
<td style="font-size: 20px;color: #2ec551">
<div class="form-group">
<input type="hidden" name="table" value="{{$table[0]->number}}">
<input type="hidden" name="table_number" value="{{$table[0]->number}}">
<label for="inputText3" class="col-form-label"></label>
{{$table[0]->number}}
</div>
</td>
<td>
<div class="col-xl-12 col-lg-12 col-md-12 col-sm-12 col-12 ">
<button class="btn btn-success" type="submit">Save</button>
</div>
</td>
</tr>
#endforeach
The name of the variables must be an array as such:
<input type="hidden" name="title[]" value="{{$product->title}}">
This way you will have an array on your backed that you can iterate. If not, you will only get one value for "title"

Controller Update method is not working in laravel

I am using laravel 5.2. Controller method store, show, and edit is working fine but update method is not working.
edit.blade is as:
#extends ('layouts.backend')
#section ('content')
<div class="pull-right">
<a class="btn btn-primary" href="{{ route('backend.index') }}"> Back</a>
</div>
<form method="PATCH" action="{{ route('backend.update', $reports->id) }}">
<div>
create report
</div>
<div>
<table>
<tr>
<td>
<div class="form-group required">
<label for="category_id" class="control-label">ID</label>
<input class="form-control" name="id" id="id" type="text" value="{{ $reports->id}}">
</div>
<div class="form-group required">
<label for="category_id" class="control-label">Category</label>
<select class="form-control" id="category" name="category"><option value="" selected="selected">Select</option><option value="1">Agriculture</option><option value="2">Food</option><option value="3">Beverage</option></select>
</div>
<div class="form-group required">
<label for="name" class="control-label">Name</label>
<input class="form-control" name="name" id="name" type="text" value="{{ $reports->name}}">
</div>
<div class="form-group required">
<label for="url" class="control-label">Url</label>
<input class="form-control" name="slug" id="slug" type="text" value="{{ $reports->slug}}">
</div>
<div class="form-group required">
<label>Brief Description</label></br>
<textarea id="brief_des" name="brief_des" rows="12" cols="70" style="width: 80%" >
{{ $reports->brief_des}}
</textarea>
</div>
<div class="form-group required">
<label>Full Description</label></br>
<textarea id="full_des" name="full_des" rows="12" cols="70" style="width: 80%">
{{ $reports->full_des}}
</textarea>
</div>
<input type="submit" value="Update"/>
</td>
<td>
</td>
</tr>
</table>
</div>
{{ Form::token() }}
</form>
#endsection
and Controller update method code is as:
public function update(Request $request, $id){
report::find($id)->update($request->all());
return redirect()->route('backend.index')
->with('success','Product Updated Successfully');
}
and route.php is as:
Route::resource('backend', 'ReportController');
when I am submitting the form then I am getting any update in my database and redirect is not working also.

SPRING MVC: Form Backed Bean Properties not declared as form fields in jsp are set to null

I was learning spring mvc. I developed a screen where on login the personal data of a user will show up.On the same screen there will be update button to update the personal data.
My problem is that in the personaldata.jsp , the user properties like username, password which are not mentioned as form fields are set to null after form submit.
Below is my personaldata.jsp
<form:form name="customerForm" id="customerForm" commandName="customerForm" method="post" >
<form:hidden path="userName" id="userName"/>
<form:hidden path="emailAddress" id="emailAddress"/>
<form:hidden path="password" id="password"/>
<div class="faq_rightin">
<div class="faq_icon"><img src='<c:url value="/images/icon19.png" />' alt=""></div>
<div class="faq_ohc2">
<h1><spring:message code="myaccount.label.personaldata" text="Personal Data"></spring:message></h1>
<span class="common ul-font-style m_top ">Welcome ${customerForm.firstName} ${customer.lastName}</span>
<span class="red"><spring:message code="myaccount.label.personalinfodesc" text="You may here enter your personal Information, enabling you to use those when you make your next booking. Doing so, your user experience is better, quicker."></spring:message></span>
<div class="m_top pd-form-box">
<div class="comm_md m_top float-left">
<div class="pd-colum1 mrg-rgt10">
<span class="pd-name-title mrg-rgt10">
<select class="select-pd-name1" id="delivery_method" >
<option class="select-pd-name1" value="0">Mr</option>
<option value="1">Mrs</option>
<option value="2">Miss</option>
</select>
</span>
<span>
<spring:message code="myaccount.label.firstname" text="First Name" var="firstname" />
<form:input path="firstName" id="firstName" cssClass="pd-form-txt-common pd-txt1 float-left shadow" placeholder="${firstname}*" />
</span>
</div>
<div class="pd-colum2 ">
<spring:message code="myaccount.label.familyname" text="Family Name" var="lastname"></spring:message>
<form:input path="lastName" id="lastName" cssClass="pd-form-txt-common pd-txt2 float-left shadow" placeholder="${lastname}*" />
</div>
</div><!--end row -->
<div class="comm_md m_top float-left">
<div class="pd-colum1 mrg-rgt10">
<div class="comm_md float-left">
<spring:message code="myaccount.label.emailaddress" text="Email-Address"></spring:message>* : ${customerForm.emailAddress}
</div>
<spring:message code="myaccount.label.changeyouremailaddress" text="Change your Email Address"></spring:message> >
</div>
<div class="pd-colum2 ">
<div class="comm_md float-left">
<spring:message code="myaccount.label.birthday" text="Birthday"></spring:message>*
</div>
<div class="comm_md float-left">
<!--<form method="post" action="">
<div class="select_md3 float-left">
<form:select path="day" id="" cssClass="select2">
<form:option value="1">1</form:option>
<form:option value="2">2</form:option>
<form:option value="3">3</form:option>
<form:option value="4">4</form:option>
</form:select>
</div>
</form>-->
<div class="select_md3 float-left">
<form:select path="day" id="birthDay" cssClass="select2" items="${days}"/>
</div>
<span class="float-left f13 p_5">/</span>
<!--<form method="post" action="">
<div class="select_md3 float-left">
<form:select path="month" id="" cssClass="select2">
<form:option value="1">1</form:option>
<form:option value="2">2</form:option>
<form:option value="3">3</form:option>
<form:option value="4">4</form:option>
</form:select>
</div>
</form>-->
<div class="select_md3 float-left">
<form:select path="month" id="birthMonth" cssClass="select2" items="${months}"/>
</div>
<span class="float-left f13 p_5">/</span>
<!--<form method="post" action="">
<div class="select_md4 float-left">
<form:select path="year" id="" cssClass="select2">
<form:option value="1">2011</form:option>
<form:option value="2">2012</form:option>
<form:option value="3">2013</form:option>
<form:option value="4">2014</form:option>
</form:select>
</div>
</form> -->
<div class="select_md4 float-left">
<form:select path="year" id="birthYear" cssClass="select2" items="${years}"/>
</div>
</div>
</div>
</div><!--end row -->
<div class="comm_md m_top float-left">
<div class="pd-colum1 mrg-rgt10">
<span>
<spring:message code="myaccount.label.code" text="Code" var="phonecode"></spring:message>
<form:input path="phoneCode" id="phoneCode" cssClass="pd-form-txt-common pd-txt3 float-left mrg-rgt10 shadow" placeholder="${phonecode}"/>
</span>
<span>
<spring:message code="myaccount.label.phonenumber" text="Phone Number" var ="phonenumber"></spring:message>
<form:input path="phoneNumber" id="phoneNumber" cssClass="pd-form-txt-common pd-txt1 float-left shadow" placeholder="${phonenumber}"/>
</span>
</div>
<div class="pd-colum2 ">
<span>
<spring:message code="myaccount.label.code" text="Code" var="mobileCode"></spring:message>
<form:input path="mobileCode" id="mobileCode" cssClass="pd-form-txt-common pd-txt3 float-left mrg-rgt10 shadow" placeholder="${mobileCode}"/>
</span>
<span>
<spring:message code="myaccount.label.mobilenumber" text="Mobile Number" var="mobileNumber"></spring:message>
<form:input path="mobileNumber" id="mobileNumber" cssClass="pd-form-txt-common pd-txt4 float-left shadow" placeholder="${mobileNumber}*"/>
</span>
</div>
</div><!--end row -->
<div class="comm_md m_top float-left">
<div class="pd-colum1 mrg-rgt10">
<form:select path="idDocument" cssClass="select-pd-name" id="idDocument">
<form:option value="0"><spring:message code="myaccount.label.identificationdocument" text="Identification Document"></spring:message></form:option>
<form:option value="1"><spring:message code="myaccount.label.passport" text="Passport"></spring:message></form:option>
<form:option value="2"><spring:message code="myaccount.label.license" text="License"></spring:message></form:option>
</form:select>
</div>
<div class="pd-colum2 ">
<span class="f13 bold"><spring:message code="myaccount.label.invoiceaddressforcompanies" text="Invoice Address for Companies"></spring:message></span>
</div>
</div><!--end row -->
<div class="comm_md m_top float-left">
<div class="pd-colum1 mrg-rgt10">
<form:input path="idNumber" cssClass="pd-form-txt-common pd-txt5 float-left shadow" placeholder="Ausweisnumber*"/>
</div>
<div class="pd-colum2 ">
<input type="checkbox" name="" class="mrgrgt5" id=" "><span class="f13"><spring:message code="myaccount.label.sameasmailaddress" text="Same as mail Address"></spring:message> </span>
</div>
</div><!--end row -->
<div class="comm_md m_top float-left">
<div class="pd-colum1 mrg-rgt10">
<span class="f13 bold"><spring:message code="myaccount.label.address" text="Address"></spring:message></span>
</div>
<div class="pd-colum2 ">
<span>
<spring:message code="myaccount.label.companyname" text="Company Name" var="companyname"></spring:message>
<form:input id="companyName" path="companyName" class="pd-form-txt-common pd-txt2 float-left mrg-rgt10 shadow" placeholder="${companyname}"/>
</span>
</div>
</div><!--end row -->
<div class="comm_md m_top float-left">
<div class="pd-colum1 mrg-rgt10">
<span>
<spring:message code="myaccount.label.street" text="Street" var="${street}"></spring:message>
<form:input path="address.street" id="street" cssClass="pd-form-txt-common pd-txt1 float-left mrg-rgt10 shadow" placeholder="${street}"/>
</span>
<span>
<form:input path="address.streetNo" id="streetNo" cssClass="pd-form-txt-common pd-txt3 float-left shadow" placeholder="No"/>
</span>
</div>
<div class="pd-colum2 ">
<span>
<spring:message code="myaccount.label.street" text="Street" var="street"></spring:message>
<form:input path="address.companyStreet" id="compStreet" cssClass="pd-form-txt-common pd-txt4 float-left mrg-rgt10 shadow" placeholder="${street}"/>
</span>
<span>
<form:input path="address.companyStreetNo" id="compStreetNo" cssClass="pd-form-txt-common pd-txt3 float-left shadow" placeholder="No"/>
</span>
</div>
</div><!--end row -->
<div class="comm_md m_top float-left">
<div class="pd-colum1 mrg-rgt10">
<span>
<spring:message code="myaccount.label.plz" text="PLZ" var="zip"></spring:message>
<form:input path="address.postalCode" id="postalCode" cssClass="pd-form-txt-common pd-txt3 float-left mrg-rgt10 shadow" placeholder="${zip}"/>
</span>
<span>
<spring:message code="myaccount.label.town" text="Town" var="compcity"></spring:message>
<form:input path="address.city" id="city" cssClass="pd-form-txt-common pd-txt1 float-left shadow" placeholder="${compcity}"/>
</span>
</div>
<div class="pd-colum2 ">
<span>
<spring:message code="myaccount.label.plz" text="PLZ" var="plzcomp"></spring:message>
<form:input path="address.companyPostalCode" id="compPostalCode" cssClass="pd-form-txt-common pd-txt3 float-left mrg-rgt10 shadow" placeholder="${plzcomp}"/>
</span>
<span>
<spring:message code="myaccount.label.town" text="Town" var="comtown"></spring:message>
<form:input path="address.companyCity" id="compCity" cssClass="pd-form-txt-common pd-txt4 float-left shadow" placeholder="${comtown}"/>
</span>
</div>
</div><!--end row -->
<div class="comm_md m_top float-left">
<div class="pd-colum1 mrg-rgt10">
<!--<select class="select-pd-name" id="delivery_method" >
<option class="select-pd-name" value="0"><spring:message code="myaccount.label.country" text="Country"></spring:message></option>
<option value="1">England</option>
<option value="2">Irland</option>
</select> -->
<spring:message code="myaccount.label.country" text="Country" var="country"></spring:message>
<form:input path="address.country" id="country" cssClass="select-pd-name" placeholder="${country}"/>
</div>
<div class="pd-colum2 ">
<!-- <select class="select-pd-name" id="delivery_method" >
<option class="select-pd-name" value="0"><spring:message code="myaccount.label.country" text="Country"></spring:message></option>
<option value="1">England</option>
<option value="2">Irland</option>
</select>-->
<spring:message code="myaccount.label.country" text="Country" var="compCountry"></spring:message>
<form:input path="address.companyCountry" id="compCountry" cssClass="select-pd-name" placeholder="${compCountry}"/>
</div>
</div><!--end row -->
<div class="comm_md m_top float-left">
<div class="pd-colum1 mrg-rgt10">
<select class="select-pd-name" id="delivery_method" >
<option class="select-pd-name" value="0"><spring:message code="myaccount.label.eticketidentification" text="E-ticket Identification"></spring:message></option>
<option value="1">England</option>
<option value="2">Irland</option>
</select>
</div>
<div class="pd-colum2 flt-rgt ">
<spring:message code="myaccount.label.vatnumber" text="VAT Number" var="vatNumber"></spring:message>
<form:input path="vatNumber" id="vatNumber" cssclass="pd-form-txt-common pd-txt2 float-left mrg-rgt10 shadow" placeholder="${vatNumber}"/>
</div>
</div><!--end row -->
<div class="comm_md m_top float-left">
<div class="pd-colum1 mrg-rgt10">
<span class="f13 blue_txt"><b>*</b><spring:message code="myaccount.label.fieldsmustbefilledout" text="Fields must be filled out"></spring:message></span>
</div>
<div class="pd-colum2 flt-rgt ">
<input type="checkbox" name="" class="mrgrgt5"><span class="f13"><spring:message code="myaccount.label.futureinformationsofspecialofferings" text="I want to have in future informations about special of ferings for t4b customers."></spring:message> </span>
</div>
</div><!--end row -->
<div class="comm_md m_top float-left">
<div class="pd-colum1 mrg-rgt10">
<select class="select-pd-name" id="delivery_method" >
<option class="select-pd-name" value="0"><spring:message code="myaccount.label.languagepreferred" text="Language ,Preferred"></spring:message></option>
<option value="1">Sizilian</option>
<option value="2">English</option>
</select>
</div>
<div class="pd-colum2 flt-rgt ">
<input type="submit" name="" id="store" class="common-btn float-right" value="<spring:message code="myaccount.label.store" text="Store"></spring:message>" />
</div>
</div><!--end row -->
</div><!--end pd-form-box -->
</div>
</div>
</form:form>
To solve this problem I have to use hidden form fields for username and password. Is there any other solution so the form fields not mentioned in jsp are not set to null?
Below is my request handler after successful login
#RequestMapping(value = "/personaldata", method = RequestMethod.GET)
public String personalData(Map<String, Object> map,
HttpServletRequest request, Principal principal) {
logger.info("Default Page");
try {
String userName = principal.getName();
logger.debug("*******User name: " + userName);
CustomerVO customerVO = customerService.findByUserName(userName);
map.put("customerForm", customerVO);
} catch (T4BException e) {
logger.error(e.getLocalizedMessage());
}
/*
* map.put("search", searchVO); if
* (request.getParameter("ajax_get_standard_content") != null &&
* request.getParameter("ajax_get_standard_content").equals("on")) {
* return "home.definition.ajax"; } else { return "home.definition"; }
*/
return "myaccount.personaldata";
}
So, I add my backing bean in the model mao.
Below is my request handler for update of data
#RequestMapping(value = "/storepersonal", method = RequestMethod.POST)
public String storePersonal(#ModelAttribute("customerForm")CustomerVO customerVO , Map<String, Object> map,
HttpServletRequest request, HttpSession session,Principal principal) {
try {
customerService.updateCustomer(customerVO);
//map.put("customerForm", customerService.findByUserName(customerVO.getUserName()));
} catch (T4BException e) {
logger.error(e.getLocalizedMessage());
}
logger.info("Store Personal Page");
/*
* map.put("search", searchVO); if
* (request.getParameter("ajax_get_standard_content") != null &&
* request.getParameter("ajax_get_standard_content").equals("on")) {
* return "home.definition.ajax"; } else { return "home.definition"; }
*/
return "myaccount.personaldata";
}
The #ModelAtrribute specified for 'customerForm' should use the existing modelAttribute present in the model map as per documentation. So, only the form fields mentioned in jsp should be set to whatever user has enetered and remaining fields of customerForm should be as it is they were in the model map before.
Here is an excerpt from the documentation:
An #ModelAttribute on a method argument indicates the argument should be retrieved from the model. If not present in the model, the argument should be instantiated first and then added to the model. Once present in the model, the argument's fields should be populated from all request parameters that have matching names.
[...]
#RequestMapping(value="/owners/{ownerId}/pets/{petId}/edit", method = RequestMethod.POST)
public String processSubmit(#ModelAttribute Pet pet) {
}
Given the above example where can the Pet instance come from? There are several options:
It may already be in the model due to use of #SessionAttributes — see the section called “Using #SessionAttributes to store model attributes in the HTTP session between requests”.
It may already be in the model due to an #ModelAttribute method in the same controller — as explained in the previous section.
It may be retrieved based on a URI template variable and type converter (explained in more detail below).
It may be instantiated using its default constructor.
So your controller should have the following:
#ModelAttribute("foo")
private Foo prepareFoo() {
// get the foo to update from the database and return it.
// Spring will store it in the model
}
#RequestMapping(...)
public ModelAndView submitForm(#ModelAttribute("foo") Foo foo) {
// Spring will pass the Foo that has been prepared and stored in the model,
// updated with the values submitted in the HTML form
}

Resources