Spring Thymeleaf twice form submit Error 400 - java

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)

Related

Retrieve input(s) from DataTable

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.

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>

JSON dropdown implemetation in JSP, getting 500 (Internal Server Error)

Please help me with this JSP dropdown that I want to implement using JSON.
I am getting 500 error:
GET http://localhost:8080/ProjectManager/getEmployeesInProject.view?projectId=1 500 (Internal Server Error)
This is the script that I am using:
Hi Guys, Please help me with this dropdown that I want to implement using JSON.
I am getting 500 error:
GET http://localhost:8080/ProjectManager/getEmployeesInProject.view?projectId=1 500 (Internal Server Error)
This is the script that I am using:
<script>
$(document).ready(function(){
$('select#projectList').change(function(e){
// Your event handler
//alert(1);
$.getJSON ("getEmployeesInProject.view", {projectId: $(this).val()},
function(j) {
alert('j.length '+j.length);
var options = '';
for (var i = 0; i < j.length; i++){
options += '<option value="' + j[i].id + '">' + j[i].name + '</option>';
}
$("select#employeeList").html(options);
});
});
});
</script>
My JSP form is :
<br />
<br />
<table width='670'>
<tr>
<td width='600'>Projects *</td>
<td>
<select id="projectList">
<c:forEach var="listProjects" items="${listProjects}"
varStatus="i">
<option value="${projectId[i.index]}">${listProjects}</option>
</c:forEach>
</select></td>
</tr>
<tr>
<td width='600'>Descriptions*</td>
<td><input type="text" id="taskDescription"></td>
</tr>
<tr>
<td width='600'>Start Date of Task[dd-mm-yyyy]*</td>
<td><input type="text" id="taskDescription"></td>
</tr>
<tr>
<td width='600'>Due Date of Task[dd-mm-yyyy]*</td>
<td><input type="text" id="taskDescription"></td>
</tr>
<tr>
<td width='600'>Who should do this? *</td>
<td><select id="employeeList">
<c:forEach var="listEmployee" items="${listEmployee}">
<option>${listEmployee}</option>
</c:forEach>
</select></td>
</tr>
<tr>
<td> <input type = "submit" value = "Add a task" /></td>
</tr>
</table>
</form:form>
This is my controller part:
#RequestMapping(value="getEmployeesInProject.view")
#Transactional
public #ResponseBody List<Employee> fetchEmployeesInProject(#ModelAttribute("project") Project project, #RequestParam(value="projectId", required=true) int projectId, ModelMap modelMap){
return assignTasksService.fetchEmployeesInProject(projectId);
}

Cannot add data into database for crud using servlet

<form action="addCustServlet" method="POST" name="frmAddUser">
<table>
<tr>
<td><h3 class="templatemo-gold">ID Number: </h3></td>
<td>
<input type="text" name="cust_id" size="12" value="<c:out value="${customer.cust_id}" />" /> <br/><br/></td>
</tr>
<tr>
<td><h3 class="templatemo-gold">Name: </h3></td>
<td><input type="text" name="custName" size="50"
value="<c:out value="${customer.custName}" />" /> <br/><br/></td>
</tr>
<tr>
<td><h3 class="templatemo-gold">Address: </h3></td>
<td><input type="text" name="custAdd" size="50"
value="<c:out value="${customer.custAdd}" />" /><br/><br/></td>
</tr>
<tr>
<td><h3 class="templatemo-gold">Region: </h3></td>
<td><input type="text" name="custRegion" size="50"
value="<c:out value="${customer.custRegion}" />" /><br/><br/></td>
</tr>
<tr>
<td><h3 class="templatemo-gold">Handphone No: </h3></td>
<td><input type="text" name="custHandphoneNo" size="50"
value="<c:out value="${customer.custHandphoneNo}" />" />><br/><br/></td>
</tr>
<tr>
<td><h3 class="templatemo-gold">Phone No: </h3></td>
<td><input type="text" name="custPhoneNo" size="50"
value="<c:out value="${customer.custPhoneNo}" />" /><br/><br/></td>
</tr>
<tr>
<td><h3 class="templatemo-gold">Email: </h3></td>
<td><input type="text" name="custEmail" size="50"
value="<c:out value="${customer.custEmail}" />" /><br/><br/></td>
</tr>
<tr>
<td> <input type="submit" name="submit" class="btn text-uppercase templatemo-btn templatemo-info-btn">Submit </td>
</tr>
</table>
</form>
Whenever I try to insert data using jsp form, it keeps executing nullPointerException as my cust_id is not auto generated or auto increment.
After I click addbutton, servlet sent to updateUser and data cannot be inserted.
Customer customer = new Customer();
customer.setCustName(request.getParameter("custName"));
customer.setCustAdd(request.getParameter("custAdd"));
customer.setCustRegion(request.getParameter("custRegion"));
customer.setCustHandphoneNo(request.getParameter("custHandphoneNo"));
customer.setCustPhoneNo(request.getParameter("custPhoneNo"));
customer.setCustEmail(request.getParameter("custEmail"));
String cust_id = request.getParameter("cust_id");
if(cust_id == null || cust_id.isEmpty())
{
dao.addUser(customer);
}
else
{
customer.setCust_id(cust_id);
dao.updateUser(customer);
}
RequestDispatcher view = request.getRequestDispatcher(LIST_USER);
request.setAttribute("customer", dao.getAllCustomer());
view.forward(request, response);
}

how to delete data from different <div>

i am loading two <div> on single page, both holding same userID. I want to delete user data from 2nd <div>. how is it possible. Here is my controller code for delete..
HTML
<div id="tab1">
<br/>
<font color="#3b73af" size="4">Partner Detail</font>
#if($editPartnerDetail)
<form id="editPartnerDetail" class="aui" onsubmit="return validateEditForm()">
<div id="Partner_Detail">
<table style="width:80%;border:none;" cellspacing="0" cellpadding="0">
<tr>
<td>Admin Name:</td><td><input type="text" value="$editPartnerDetail.adminName" id="editAdminName" name="editAdminName" size="55" /></td>
</tr>
<tr>
<td>Email:</td><td><input type="text" value="$editPartnerDetail.email" id="editEmail" name="editEmail" size="55" /></td>
</tr>
<tr>
<td>Phone:</td><td><input type="text" value="$editPartnerDetail.phone" id="editPhone" name="editPhone" size="55" /></td>
</tr>
<input type="hidden" value="$editPartnerDetail.partnerDetailId" id="editPartnerDetailId" name="editPartnerDetailId" size="55" />
<input type="hidden" value="$editPartnerDetail.partnerSiteId" id="editPartnerSiteId" name="editPartnerSiteId" size="55" />
<tr>
<td></td><td><input type="submit" value="Update" class="button" /> Cancel</td>
</tr>
</table>
</div> <br/><br/><br/>
</form>
#else
<form id="addPartnerDetail" class="aui" onsubmit="return validateForm()">
<div id="Partner_Detail">
<table style="width:80%;border:none;" cellspacing="0" cellpadding="0">
<tr>
<td>Admin Name:</td><td><input type="text" value="" id="adminName" name="adminName" size="55" autocomplete="off"/></td>
</tr>
<tr>
<td>Email:</td><td><input type="text" value="" id="email" name="email" size="55" autocomplete="off"/></td>
</tr>
<tr>
<td>Phone:</td><td><input type="text" value="" id="phone" name="phone" size="55" autocomplete="off"/></td>
</tr>
<input type="hidden" value="$siteId" id="addPartnerSiteId" name="addPartnerSiteId" size="55" />
<tr>
<td></td><td><input type="submit" value="Add" class="button" /></td>
</tr>
</table>
</div> <br/><br/><br/>
</form>
#end
<div id="Partner_Detail">
<table style="width:80%">
<tr>
<th bgcolor="#F2F5A9">Admin Name</th>
<th bgcolor="#F2F5A9">Email</th>
<th bgcolor="#F2F5A9">Phone</th>
<th bgcolor="#F2F5A9">Action</th>
</tr>
#foreach( $partnerDetail in $partnerDetailList )
<tr>
<td>$partnerDetail.adminName</td>
<td>$partnerDetail.email</td>
<td>$partnerDetail.phone</td>
<td align="center">Edit | Delete</td>
</tr>
#end
</table>
</div>
</div>
<div id="tab2">
#if($editPartnerSite2)
<form id="editsite2" class="aui">
<div id="edit_Partner_site2">
<input type="text" value="$editPartnerSite2.partnerSite" id="editPartnerSite" name="editPartnerSite" size="55" />
<input type="hidden" value="$editPartnerSite2.partnerId" id="editPartnerSiteId" name="editPartnerSiteId" size="55" />
<input type="hidden" value="site" id="page" name="page" size="55" />
<input type="submit" value="Update" class="button">
Cancel
#if($isSiteupdated == false)
<div style="color:red;">Cannot Edit. Same partner site already exist.</div>
#end
</div>
</br>
</form>
#else
<form id="addsite" class="aui">
<div id="add_Partner_Site">
<input type="hidden" value="site" id="page" name="page" size="55" />
<input type="text" id="partnersite" name="partnersite" size="55" autocomplete="off" value="$!existingSite"/>
<br/><br/><input type="submit" value="Add" class="button" /></td>
#if($isSiteAdded == false)
<div style="color:red;">Cannot add. Same partner site already exist.</div>
#end
</div> <br/><br/><br/>
</form>
#end
<table>
<tr>
<th bgcolor="#F2F5A9">Partner Site</th>
<th bgcolor="#F2F5A9">Action</th>
</tr>
#foreach( $partnerSite in $partnerSiteList )
<tr>
<td>$partnerSite.partnerSite</td>
<td align="center">Edit | Delete</td>
</tr>
#end
</table>
<div>
Controller
else if (pageName != null && pageName.equals("partnerDetail")) {
Map<String, Object> context = new HashMap<String, Object>();
if (request.getParameter("nameId") != null && request.getParameter("nameId") != "") {
siteId = Integer.parseInt(request.getParameter("nameId"));
String mode = request.getParameter("mode");
if (mode != null && mode.equals("delete")) {
String pdId = request.getParameter("pdId");
if (pdId != null && pdId != "") {
partnerDetailService.deletePartneDetail(Integer.parseInt(pdId));
}
}
if (mode != null && mode.equals("edit")) {
String pdId = request.getParameter("pdId");
int partnerDetailID = Integer.parseInt(pdId);
if (pdId != null && pdId != "") {
PartnerDetail editPartnerDetail = partnerDetailService.getPartneDetailById(partnerDetailID);
context.put("editPartnerDetail", editPartnerDetail);
}
}
}
if (request.getParameter("nameId") != null && request.getParameter("nameId") != "") {
siteId = Integer.parseInt(request.getParameter("nameId"));
String mode = request.getParameter("mode");
if (mode != null && mode.equals("deleteTab2")) {
String sId = request.getParameter("sId");
if (sId != null && sId != "") {
partnerSiteService.deletePartnerSite(Integer.parseInt(sId));
}
}
}
//===========================
context.put("siteId", siteId);
List<PartnerDetail> partnerDetailList = partnerDetailService.getAllDetailByPartnerSiteID(siteId);
context.put("partnerDetailList", partnerDetailList);
String partnerId = request.getParameter("nameId");
int pID = Integer.parseInt(partnerId);
List<PartnerSite> partnerSiteList = partnerDetailService.getAllPartnerSiteById(pID);
context.put("partnerSiteList", partnerSiteList);
response.setContentType("text/html;charset=utf-8");
renderer.render("templates/admin/partnerDetail.vm", context,response.getWriter());
help me out..
You should never use the same ID on two elements!
It's better to use class instead. The id-attribute is reserved for unique idintifiers

Categories

Resources