Retrieve input(s) from DataTable - java

Need some advice how should I retrieve a list of exhibits.
In my html template below, I only put one record of exhibit. If i were to put additional rows/records of exhibit, how do i go about mapping them to the controller.
HTML Template
<h3>Exhibit Details</h3>
<div class="table-responsive">
<table id="exhibitTable"
class="table table-bordered table-hover table-striped">
<thead>
<tr>
<th>Exhibit Type</th>
<th>Description</th>
<th>Marking</th>
<th>Remarks</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<div class="form-group col-md-3">
<div class="cols-sm-10">
<select class="form-control selectpicker cols-md-3"
th:value="${exhibit.exhibitType}" id="exhibitType"
name="exhibitType" roleId="exhibitType">
<option value="">Select Type</option>
<option>Desktop</option>
<option>Laptop</option>
<option>Mobile Device</option>
<option>Portable Storage</option>
<option>Server</option>
<option>Video System</option>
<option>Save As</option>
<option>Others</option>
</select>
</div>
</div>
</td>
<td>
<div class="form-group col-md-3">
<input type="text" name="exhibitDescription"
id="exhibitDescription"
th:value="${exhibit.exhibitDescription}" />
</div>
</td>
<td>
<div class="form-group col-md-3">
<input type="text" name="exhibitMarking" id="exhibitMarking"
th:value="${exhibit.exhibitMarking}" />
</div>
</td>
<td><div class="form-group col-md-3">
<input type="text" name="exhibitRemarks" id="exhibitRemarks"
th:value="${exhibit.exhibitRemarks}" />
</div></td>
</tr>
</tbody>
</table>
</div>
Controller
#RequestMapping(value = "/register", method = RequestMethod.POST)
public String registerIncidentPost(#ModelAttribute("incident") Incident incident,
#ModelAttribute("exhibit") Exhibit exhibit, Principal principal) throws Exception {
long year = Calendar.getInstance().get(Calendar.YEAR);
incident.setIncidentYear(year + "");
Long refNo = incidentService.findMaxRefNoCurrentYear(year + "");
if (refNo == null)
refNo = (long) 1;
else
refNo += 1;
incident.setIncidentRefNo(refNo);
incident.setIncidentStatus(Incident.INCIDENT_REGISTERED);
incident.setIncidentOpeningTimestamp(new Date());
User user = userService.findByUsername(principal.getName());
incident.setIncidentCreatedBy(user);
incidentService.createIncident(incident);
exhibitService.createExhibit(exhibit);
return "redirect:/incident";
}
I've attempted to add the following to my template
<tr data-th-each="exhibit:${exhibitList}">
and the following to my controller
#ModelAttribute("exhibitList") ArrayList<Exhibit> exhibitList
but did not work.
Thanks in advance.

I can only assume this is vb.net since you didn't specify. You need to pass in the complete dataset to the page. Each item in the dataset will be one pre-loaded instance of the model. Then you can do a for each loop on the page itself and generate the html dynamically. Hope this helps.

Related

Object received from springboot backend and resent back has fields containing null values

I use an angular+springboot web application in which an object ( for this example- clinic object ) fetched from springboot in angular is not modified, and then is sent back to springboot, and some of its prperties's values for no apparent reason just become null, and others ( a boolean property get value of false, and integer properties get value of 0 ) get default values.
This is a table in which clinic objects are desplayed, and from which a modal to update a clinic is opened.
<table class="table">
<thead>
<tr>
<th scope="col" style="text-align:right;"></th>
<th scope="col" style="text-align:right;">State</th>
<th scope="col" style="text-align:right;">Foundation Year</th>
<th scope="col" style="text-align:right;">Supervisor</th>
<th scope="col" style="text-align:right;">Clinic Name</th>
</tr>
</thead>
<tbody>
<tr [ngClass]="{'not-active-clinic':!clinic.active}" *ngFor="let clinic of clinics">
<td style="text-align:right;">
<button class="btn-primary mr-1" (click)="openEditModal(editModal,clinic)"><i
class="fa fa-edit"></i></button>
<!--Edit Modal -->
<ng-template #editModal let-modal>
<div class="modal-header">
<h4 class="modal-title" id="modal-basic-title">Clinic Edit</h4>
<button style="margin-left: 0;" type="button" class="close" aria-label="Close"
(click)="modal.dismiss('Cross click')">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form dir="rtl">
<div class="row">
<div class="col-3">
<label>
Clinic Name: </label>
</div>
<div class="col-9">
<input style="width: 100%;" type="text" name="clinicName"
[(ngModel)]="edittedClinic.clinicName">
</div>
</div>
<div class="row">
<div class="col-3">
<label>
Supervisor</label>
</div>
<div class="col-9">
<select (change)="onChange()" style="width: 100%;"
name="clinicalSupervisorId"
[(ngModel)]="edittedClinic.clinicalSupervisorId">
<option *ngFor="let s of supervisors" [value]="s.id">
{{s.firstName+' '+s.lastName}}
</option>
</select>
</div>
</div>
<div class="row">
<div class="col-3">
<label>
description:</label>
</div>
<div class="col-9">
<textarea style="width: 100%;height:350px"
[(ngModel)]="edittedClinic.description" name="description">
</textarea>
</div>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-outline-dark"
(click)="modal.close('Save click');onEdit(clinic)">Edit</button>
</div>
</ng-template>
<button class="btn btn-sm btn-danger btn-delete-account"
(click)="openDeleteModal(deleteModal)">
<span class="spinner-border spinner-border-sm"><i
class="fa fa-trash-alt"></i></span>
</button>
<!--Delete Modal -->
</td>
<td style="text-align:right;">
<button (click)="onChangeClinicState(clinic)">
{{clinic.active?"Add To Archive":"Restore"}}</button>
</td>
<td style="text-align:right;">{{clinic.yearFounded}}</td>
<td style="text-align:right;">{{clinic.clinicalSupervisorId}}</td>
<td style="text-align:right;">{{clinic.clinicName}}</td>
</tr>
</tbody>
</table>
This the method in angular to fetch the edited object to send it to service in which there is the http call to send the clinic object to springboot:
onEdit(clinicToEdit:Clinic)
{
this.dashboardService.updateClinicDetails(this.edittedClinic).subscribe(
data=>{
clinicToEdit=Object.create(this.edittedClinic);
},
err=>{
}
)
}
This is the method in the service to send the http put call
updateClinicDetails(clinic:Clinic)
{
return this.http.put(BASE_URL +`/api/v1/clinic/${clinic.clinicName}`,clinic);
}
This is the API method in springboot to get the clinic object sent from angular.
#PutMapping(path = "{clinicName}")
public int updateClinicById(#PathVariable("clinicName") String clinicName, #RequestBody Clinic clinicToUpdate)
{
return clinicService.updateClinic(clinicName, clinicToUpdate);
}
This is the constructor of clinic object invoked in order to fetch the JSON sent to springboot from angular.
public Clinic(#JsonProperty("clinicName") String clinicName,
#JsonProperty("clinicalSupervisorId") int clinicalSupervisorId,
#JsonProperty("description") String description, #JsonProperty("yearFounded") int yearFounded,
#JsonProperty("active") boolean active)
{
this.clinicName = clinicName;
this.clinicalSupervisorId = clinicalSupervisorId;
this.yearFounded = yearFounded;
this.description = description;
this.active = active;
}
Now, the thing is when modified, those mentioned properties don't contain null values, or their default values, What is the explanation to this, and what's the best way to solve it?

Passing thymeleaf information to a hidden form

I am trying to pass the information from a thymeleaf list and trying to add it to database.
I am getting data from the tmdb and it will be changing so i display the information obtain to the endpoint "/LatestMovies" this information is not saved in the db and ether should it be. so i am trying to add a save button for the custumer to add the movie listed.(its simple it just haves movieid and moviename)
Showing the movies listed i have no problem and it works fine but where i get error is when i add a hidden form. The current code i have is this:
<div class="container">
<table class="table table-hover">
<tr>
<th>Id</th>
<th>Name</th>
</tr>
<tr th:each="LatestMovies : ${latestMovies}">
<td th:text="${LatestMovies.id}"></td>
<td th:text="${LatestMovies.movieName}"></td>
<td>
<form action="#" th:action="#{/LatestMovies}" th:object="${addMovies}" method="post">
<p><input type="hidden" th:field="*{id}" th:attr="value = ${LatestMovies.id}" /></p>
<p><input type="hidden" th:field="*{movieName}" th:attr="value = ${LatestMovies.movieName}" /></p>
<p><input type="submit" value="Submit" /></p>
</form>
</td>
</tr>
</table>
#Controller
public class LatestMoviesController {
#Autowired
private LatestMoviesDao listOfMovies;
#Autowired
private savedMoviesDao movieRepo;
#GetMapping("/LatestMovies")
public String prueba(Model model) {
TmdbMovies movies = new TmdbApi("22914f477aaa3e7f86c6f5434df8d1eb").getMovies();
ResultsPage<MovieDb> movie = movies.getPopularMovies("en", 1);
for(int i=0; i <= 19; i++){
int movieId = movie.getResults().get(i).getId();
String movieName = movie.getResults().get(i).toString();
listOfMovies.save(new LatestMovies(movieId, movieName));
}
model.addAttribute("latestMovies", listOfMovies.findAll());
return "index";
}
#PostMapping("/LatestMovies")
public String save(#ModelAttribute("addMovies") Model model, SavedMovies addMovies) {
movieRepo.save(addMovies);
return "index";
}
}
Thx in advance
First, let's change your form. You don't need to add a new object to it, since you are already iterating through a list of them. That way, you will also avoid having to add the value for each field manually using th:attr. What we are gonna do, is send the required params separately and then build our movie object with them.
<div class="container">
<table class="table table-hover">
<tr>
<th>Id</th>
<th>Name</th>
</tr>
<tr th:each="LatestMovies : ${latestMovies}">
<td th:text="${LatestMovies.id}"></td>
<td th:text="${LatestMovies.movieName}"></td>
<td>
<form th:action="#{/LatestMovies}" method="post">
<p><input type="hidden" th:value="${LatestMovies.id}" name="id"/></p>
<p><input type="hidden" th:value="${LatestMovies.movieName}" name="name"/></p>
<p><input type="submit" value="Submit"/></p>
</form>
</td>
</tr>
</table>
</div>
Now, on your controller, do the following modifications.
#PostMapping("/LatestMovies")
public String save(#RequestParam("id") Integer id, #RequesParam("name") String name) {
SavedMovies movie = new SavedMovies();
movie.setId(id);
movie.setName(name);
movieRepo.save(movie);
return "index";
}
These changes should do the trick.

Removing just one Row in table - SpringBoot & Java & Thymeleaf

New to Spring-boot and Java and Thymeleaf...Trying to make it so the trash button deletes only one row in this table. Right now it if any trash button is clicked, all table rows are deleted.
I ran the debugger and my controller is picking up the rowId for whichever button is clicked, so not sure why it's deleting all rows and not just the one. Any ideas?
//code that loads form and table (table is made up of Ams360Policies)
#GetMapping("/directBind")
public String getDirectBind(Model model){
List<String> businessAgencies = new ArrayList<String>();
businessAgencies.add("Personal");
businessAgencies.add("Commercial");
businessAgencies.add("Life");
businessAgencies.add("Benefits");
businessAgencies.add("Health");
businessAgencies.add("Non P and C");
model.addAttribute("businessAgencies", businessAgencies);
DirectBind directBind = new DirectBind();
List<Ams360Policy> ams360Policies = new ArrayList();
Ams360Policy ams360Policy = new Ams360Policy();
ams360Policies.add(ams360Policy);
model.addAttribute("ams360Policies", ams360Policy);
List<String> billTypeList = new ArrayList<String>();
billTypeList.add("Direct Bill");
billTypeList.add("Agency Bill");
model.addAttribute("billTypeList", billTypeList);
ams360Policy.setBillTypeOptions(billTypeList);
List<String> businessAgencyList = new ArrayList<String>();
directBind.setBusinessAgencyList(businessAgencyList);
model.addAttribute("directBind", directBind);
return "directBind";
}
//code to add a Row to table
#RequestMapping(value="/directBind", params="addPolicy")
public String addPolicy(final DirectBind directBind, Model model){
List<Ams360Policy> ams360Policies = directBind.getAms360Policies();
Ams360Policy ams360Policy = new Ams360Policy();
ams360Policies.add(ams360Policy);
model.addAttribute("ams360Policies", ams360Policies);
List<String> billTypeList = new ArrayList<String>();
billTypeList.add("Direct Bill");
billTypeList.add("Agency Bill");
model.addAttribute("billTypeList", billTypeList);
ams360Policy.setBillTypeOptions(billTypeList);
List<String> businessAgencyList = new ArrayList<String>();
directBind.setBusinessAgencyList(businessAgencyList);
return "directBind";
}
//code to Remove row of table
#RequestMapping(value = "/directBind", params="removeRow")
public String removeRow(final DirectBind directBind, final HttpServletRequest req, Model model){
final Integer rowId = Integer.valueOf(req.getParameter("removeRow"));
List<Ams360Policy> ams360Policies = directBind.getAms360Policies();
model.addAttribute("ams360Policies", ams360Policies);
directBind.setAms360Policies(ams360Policies);
Ams360Policy ams360Policy = new Ams360Policy();
List<String> billTypeList = new ArrayList<String>();
billTypeList.add("Direct Bill");
billTypeList.add("Agency Bill");
model.addAttribute("billTypeList", billTypeList);
ams360Policy.setBillTypeOptions(billTypeList);
List<String> businessAgencyList = new ArrayList<String>();
directBind.setBusinessAgencyList(businessAgencyList);
directBind.getAms360Policies().remove(1);
model.addAttribute("directBind", directBind);
return "directBind";
}
//html code for table
<div>
<h4 style="display: inline;">AMS360 Policy Setup</h4>
<input type="submit" formnovalidate="formnovalidate" name="addPolicy" class="btn btn-default" style="margin-left: 1rem; margin-bottom: 1rem;" value="+"></input>
</div>
<div class="col-sm-12">
<hr/>
<table class="table table-striped AMSTable" data-classes="table-no-bordered" data-striped="true" data-show-columns="true" data-pagination="true">
<thead>
<tr>
<th>Policy Number</th>
<th>Policy Term Start Date</th>
<th>Policy Term End Date</th>
<th>Line of Coverage</th>
<th>Parent Company</th>
<th>Writing Company</th>
<th>Bill Type</th>
<th>Quote Premium</th>
<th>Commission</th>
</tr>
</thead>
<tbody>
<tr id="newPolicyRow" th:each="ams360Policy, stat : ${ams360Policies}">
<td> <input type="text" class="form-control" th:field="*{ams360Policies[__${stat.index}__].policyNumber}"/></td>
<td> <input type="text" class="form-control" th:field="*{ams360Policies[__${stat.index}__].policyTermDateStart}"/></td>
<td> <input type="text" class="form-control" th:field="*{ams360Policies[__${stat.index}__].policyTermDateEnd}"/></td>
<td> <input type="text" class="form-control" th:field="*{ams360Policies[__${stat.index}__].lineOfCoverage}"/></td>
<td> <input type="text" class="form-control" th:field="*{ams360Policies[__${stat.index}__].parentCompany}"/></td>
<td> <input type="text" class="form-control" th:field="*{ams360Policies[__${stat.index}__].writingCompany}"/></td>
<td id="billTypeCell">
<div th:each="billType : ${billTypeList}">
<input type="checkbox" th:field="*{ams360Policies[__${stat.index}__].billTypeOptions}" th:value="${billType}"/>
<label th:text="${billType}" id="billTypeLabel"></label>
</div>
</td>
<td> <input type="text" class="form-control" th:field="*{ams360Policies[__${stat.index}__].quotePremium}"/></td>
<td> <input type="text" class="form-control" th:field="*{ams360Policies[__${stat.index}__].commission}"/></td>
<td class="text-right"> <button type="submit" name="removeRow" th:value="${stat.index}" class="btn btn-danger" ><span class="fa fa-trash"></span></button></td>
</tr>
</tbody>
</table>
</div>
When I debug I get the following...
//html code for table
<div>
<h4 style="display: inline;">AMS360 Policy Setup</h4>
<input type="submit" formnovalidate="formnovalidate" name="addPolicy" class="btn btn-default" style="margin-left: 1rem; margin-bottom: 1rem;" value="+"></input>
</div>
<div class="col-sm-12">
<hr/>
<table class="table table-striped AMSTable" data-classes="table-no-bordered" data-striped="true" data-show-columns="true" data-pagination="true">
<thead>
<tr>
<th>Policy Number</th>
<th>Policy Term Start Date</th>
<th>Policy Term End Date</th>
<th>Line of Coverage</th>
<th>Parent Company</th>
<th>Writing Company</th>
<th>Bill Type</th>
<th>Quote Premium</th>
<th>Commission</th>
</tr>
</thead>
<tbody>
<tr id="newPolicyRow" th:each="ams360Policy, stat : ${ams360Policies}">
<td> <input type="text" class="form-control" th:field="*{ams360Policies[__${stat.index}__].policyNumber}"/></td>
<td> <input type="text" class="form-control" th:field="*{ams360Policies[__${stat.index}__].policyTermDateStart}"/></td>
<td> <input type="text" class="form-control" th:field="*{ams360Policies[__${stat.index}__].policyTermDateEnd}"/></td>
<td> <input type="text" class="form-control" th:field="*{ams360Policies[__${stat.index}__].lineOfCoverage}"/></td>
<td> <input type="text" class="form-control" th:field="*{ams360Policies[__${stat.index}__].parentCompany}"/></td>
<td> <input type="text" class="form-control" th:field="*{ams360Policies[__${stat.index}__].writingCompany}"/></td>
<td id="billTypeCell">
<div th:each="billType : ${billTypeList}">
<input type="checkbox" th:field="*{ams360Policies[__${stat.index}__].billTypeOptions}" th:value="${billType}"/>
<label th:text="${billType}" id="billTypeLabel"></label>
</div>
</td>
<td> <input type="text" class="form-control" th:field="*{ams360Policies[__${stat.index}__].quotePremium}"/></td>
<td> <input type="text" class="form-control" th:field="*{ams360Policies[__${stat.index}__].commission}"/></td>
<td class="text-right"> <button type="submit" name="removeRow" th:value="${stat.index}" class="btn btn-danger" ><span class="fa fa-trash"></span></button></td>
</tr>
</tbody>
</table>
</div>

Spring Thymeleaf twice form submit Error 400

i have a thymeleaf form that can validate data from the database through spring controller, the data validation works fine, but when i want to validate with different data after validation it give me an Error 400, there's no error in the stack trace, so i don't know how how to fix this, maybe because of my bad logic, because i'm newbie at this..
here's the form
<form th:name="memberRkiForm" id="memberRkiForm" th:action="#{/}" th:object="${formResult}"
method="POST">
<div>
<table id="form">
<tr>
<td colspan="7" height="40"><img class="formlogo"
th:src="#{/resources/img/docicon.png}">
<h3 class="formHeader"><b><u>REGISTER MANUAL</u></b></h3></td>
</tr>
<tr>
<td>
<label>Provider Name </label>
</td>
<td><label>:</label></td>
<td>
<input type="text" th:value="${providerId}" name="providerId" style="width:275px;"
readonly="readonly" hidden="hidden"> </input>
<input type="text" th:value="${providerName}" name="providerName" style="width:275px;"
readonly="readonly"> </input>
</td>
<td class="sep"></td>
</tr>
<tr>
<td>
<label>Member Card Number* </label>
</td>
<td><label>:</label></td>
<td>
<input type="text" name="cardNumber" th:field="*{cardNumber}"
onkeypress="return isNumberKey(event)"
style="width:190px; display: inline;"> </input>
<input id="checkCardNum" class="default-button" type="submit" style="display: inline;"
value="Validasi">
</td>
<td width="500">
<div class="error" style="display:inline;color:red;">
<p id="cardNumError" style="margin-left:15px;" th:text="${cardNumError}"></p>
</div>
</td>
<td class="sep"></td>
</tr>
<tr>
<td>
<label>Member Name </label>
</td>
<td><label>:</label></td>
<td>
<input type="text" th:value="${memberName}" name="memberName" style="width:275px;"
readonly="readonly"> </input>
</td>
<td class="sep"></td>
</tr>
<tr>
<td>
<label>Date Of Birth </label>
</td>
<td><label>:</label></td>
<td>
<input type="text" th:value="${birthday}" name="birthday" style="width:275px;"
readonly="readonly"> </input>
</td>
<td class="sep"></td>
</tr>
<tr>
<td><label>Client Name </label></td>
<td><label>:</label></td>
<td>
<input type="text" th:value="${clientName}" name="clientName" style="width:275px;"
readonly="readonly"> </input>
</td>
<td class="sep"></td>
</tr>
<tr>
<td>
<label>Admission Date </label>
</td>
<td><label>:</label></td>
<td>
<input id="datepicker" type="text"
style="margin-top:4px;width:230px;display:inline-block;"/>
<span class="calendarbox"><img th:src="#{/resources/img/calendar.png}" height="25"
width="35"></span>
</td>
<td class="sep"></td>
</tr>
<tr>
<td><label>Claim Service* </label></td>
<td><label>:</label></td>
<td>
<input type="text" th:value="${selectServiceIsEnabled}" name="selectServiceIsEnabled"
style="width:275px;" readonly="readonly" hidden="hidden"> </input>
<select id="selectservice" th:field="*{caseCategoryList}" class="selectcss"
style="width:275px;margin-left: 5px;" disabled="disabled">
<option th:each="case : ${caseCategoryList}" th:value="${case.caseCategoryId}"
th:text="${case.caseCategoryName + ' - ' + case.caseCategoryCode}"></option>
</select>
</td>
<td width="500">
<span class="error" style="display: inline;color:red;"><p id="select_error"></p></span>
</td>
<td class="sep"></td>
</tr>
<tr colspan="7" class="jumper"></tr>
<tr>
<td>
<input id="addMember" class="remodal-confirm" type="submit" name="action"
value="Register"/>
<input class="remodal-cancel" type="reset" value="Clear"/>
</td>
</tr>
</table>
</div>
</form>
when validate button is clicked, the form action goes to a spring controller that check the card number to the database (checkCardNum), then if the data validation return true, the form will be automatically filled by the data that related to the card number, after the form's filled with the data, i want to check validation with another card number (different from the first validated card number), but it give me an error 400.
here's my controller
#PreAuthorize("hasAuthority('"+ACLConstant.MENU_REGISTRATIONMEMBERRKI+"')")
#RequestMapping(value="/member-rki-form",method={RequestMethod.GET , RequestMethod.POST} )
public String memberrkiform(Model model, HttpServletRequest request, #ModelAttribute("formResult") MemberRkiForm formResult){
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
UserAuth userAuth = (UserAuth)auth.getPrincipal();
String[] cols = {"username", "deletedStatus"};
Object[] values = {userAuth.getUserName(), 0};
Users user = userService.findUserByColsAndValues(cols, values);
int userid = user.getUserId();
Users currentUser = userService.findUserByPK(userid);
Provider provider = currentUser.getProvider();
model.addAttribute("providerId", provider.getProviderId());
model.addAttribute("providerName", currentUser.getFirstName());
model.addAttribute("cardNumber", formResult.getcardNumber());
model.addAttribute("cardNumError", formResult.getErrorMsg());
model.addAttribute("memberName", formResult.getMemberName());
model.addAttribute("birthday", formResult.getBirthday());
model.addAttribute("clientName", formResult.getClientName());
model.addAttribute("caseCategoryList", formResult.getCaseCategoryList());
model.addAttribute("selectServiceIsEnabled", formResult.getSelectServiceIsEnabled());
return "memberrki/member-rki-form";
}
#RequestMapping(value="/checkCardNum",method={RequestMethod.GET , RequestMethod.POST})
public String checkCardNum(#ModelAttribute("formResult") MemberRkiForm formResult, Model model, HttpServletRequest request, RedirectAttributes redirectFormData){
String errorMsg = "";
String cardNumber = formResult.getcardNumber();
if(cardNumber==null || cardNumber==""){
errorMsg="Card Number Data Is Required";
}
else{
String[] cols = {"currentCardNumber", "deletedStatus" , "subscriptionStatus"};
Object[] values = {formResult.getcardNumber(), 0 , 1};
Member member = memberService.findMemberByColsAndValues(cols, values);
if(member==null){
errorMsg="Member Not Found";
}
else{
Member validatedMember = memberService.findMemberByPK(member.getMemberId());
Client validatedMemberClient = validatedMember.getClient();
formResult.setMemberName(validatedMember.getFirstName());
formResult.setBirthday(validatedMember.getBirthday().toString());
formResult.setClientName(validatedMemberClient.getClientName());
MemberProductSearchParams memberProductParams = new MemberProductSearchParams();
memberProductParams.setMember(validatedMember);
memberProductParams.setDeletedStatus(0);
memberProductParams.setSubscriptionStatus(1);
Page<MemberProduct> memberProductPage = memberService.findMemberProductListing(memberProductParams, null);
List<MemberProduct> memberProductLists = memberProductPage.getContent();
if(memberProductPage==null || memberProductLists==null){
/*System.out.println("NO PRODUCT FOUND");*/
errorMsg="NO PRODUCT AVAILABLE";
}
else{
List<Product> productList = new ArrayList<Product>();
List<CaseCategory> caseCategoryList = new ArrayList<CaseCategory>();
for(int i=0; i<memberProductLists.size(); i++){
String[] productCols = {"productId", "deletedStatus"};
Object[] productValues = {memberProductLists.get(i).getProduct().getProductId(), 0};
Product products = productService.findProductByColsAndValues(productCols, productValues);
productList.add(products);
String[] caseCategoryCols = {"caseCategoryId", "deletedStatus"};
Object[] caseCategoryValues = {productList.get(i).getCaseCategory().getCaseCategoryId(), 0};
CaseCategory caseCategories = caseCategoryService.findCaseCategoryByColsAndValues(caseCategoryCols, caseCategoryValues);
caseCategoryList.add(caseCategories);
}
formResult.setCaseCategoryList(caseCategoryList);
}
formResult.setSelectServiceIsEnabled("true");
}
}
formResult.setErrorMsg(errorMsg);
formResult.setcardNumber(cardNumber);
redirectFormData.addFlashAttribute("formResult", formResult);
formResult = new MemberRkiForm();
return "redirect:/memberrki/member-rki-form";
}
}
maybe someone here can help me to solve the problem,
Thx in advance.. (sorry for my bad english)

unable to bind ModelMap through ajax call in Spring MVC

MY JSP PAGE:
<form action="manageparentexamforchildren.htm" class="form-horizontal form-bordered" >
<div class="form-body">
<div class="form-group">
<label class="control-label col-md-1"><spring:message code="label.parent.children"/></label>
<div class="col-md-3">
<select name="parent.children" class="form-control" id="children" required="true" >
<option value="">-<spring:message code="label.select"/>-</option>
<c:forEach items="${studentsOfThisParent}" var="student">
<option value="${student.id}">${student.firstName} ${student.lastName}</option>
</c:forEach>
</select>
</div>
</div>
</div>
<div class="form-actions fluid">
<div class="row">
<div class="col-md-12">
<div class="col-md-offset-3 col-md-9">
<button type="submit" class="btn blue"><i class="icon-ok"></i><spring:message code='button.search'/></button>
<button type="button" onclick="javascript:history.go(-1);" class="btn red default"><spring:message code='button.cancel'/></button>
</div>
</div>
</div>
</div>
</form>
<c:forEach items="${modelList}" var="examination">
<tr>
<td><b><spring:message code="label.examination.schoolexam"/></b>:<c:out value="${examination.schoolExam.name}" /></td>
</tr>
<table border="1" width="1000" height="200" class="table table-bordered table-hover">
<thead> <tr><th class="active"><spring:message code="label.examination.subjects"/></th><th class="active"><spring:message code="label.exam.Date"/></th><th class="active"><spring:message code="label.exam.maxmarks"/></th></tr></thead>
<tbody>
<c:forEach items="${examination.examinationSubjects}" var="examinationSubject" varStatus="status">
<tr>
<td class="success"><c:out value="${examinationSubject.subjects.name}" /></td>
<td class="success" ><c:out value="${examinationSubject.date}" /></td>
<td class="success"><c:out value="${examinationSubject.maxMarks}" /></td>
</tr>
</c:forEach>
</tbody>
</table>
</c:forEach>
MY CONTROLLER:
#RequestMapping(value="/manageparentexam.htm", method=RequestMethod.GET)
public String manageparentexam(ModelMap modelMap,HttpServletRequest request )
{
Parent parent = parentService.getParentById(getLoggedInUser().getId());
List <Student> studentsOfThisParent=parentService.getStudentsOfThisParent(getLoggedInUser().getId());
Student student=null;
student=parent.getStudentAdmission().get(0).getStudent();
modelMap.addAttribute("modelList",student.getStudentAdmission().getClasses().getExamination());
setupCreate(modelMap, request);
return "tileDefinition.manageparentexam-"+getNameSpace();
}
#RequestMapping(value="/manageparentexamforchildren.htm", method=RequestMethod.GET)
public void manageparentexamforchildren(ModelMap modelMap,HttpServletRequest request )
{
Long studentId=Long.valueOf(request.getParameter("parent.children"));
modelMap.addAttribute("modelList",studentService.getById(studentId).getStudentAdmission().getClasses().getExamination());
setupCreate(modelMap, request);
}
here my requirement is,when ever,i select a value in select box,then the table should get updated through ajax,here i am unable to bind the model list through ajax call . . .
What I would do is separate the table in another jsp. yourTable.jsp like this
<table border="1" width="1000" height="200" class="table table-bordered table-hover">
<thead> <tr><th class="active"><spring:message code="label.examination.subjects"/></th><th class="active"><spring:message code="label.exam.Date"/></th><th class="active"><spring:message code="label.exam.maxmarks"/></th></tr></thead>
<tbody>
<c:forEach items="${examination.examinationSubjects}" var="examinationSubject" varStatus="status">
<tr>
<td class="success"><c:out value="${examinationSubject.subjects.name}" /></td>
<td class="success" ><c:out value="${examinationSubject.date}" /></td>
<td class="success"><c:out value="${examinationSubject.maxMarks}" /></td>
</tr>
</c:forEach>
</tbody>
</table>
Then you include this jsp in your main mapge inside a div
<div id="yourTable">
<c:jsp include="yourTable.jsp/>
</div>
Then in your select you have to add a listener and when something has change you need to make a JQuery load lo reload the table rendering the table from the controller again with all the changes that you want
$('#yourTable').load("url of your controller where you will render yourTable.jsp");
And in the controller you will render yourTable.jsp and you will add in the ModelAndView object the examinationSubject

Categories

Resources