How to interact with table on webpage with Java? - java

I'm trying to make a program for work to automate a spreadsheet that we maintain. The information is on a third party website that we log in to and then scroll through a bunch of pages and then a table is there with all of the info in it. I used selenium webdriver to open internet explorer, log you in, then navigate you to the correct page but I don't know how to interact with the table. When I inspect element in Gooogle chrome, there is no ID or name showing up for the table or any of its cells. Thanks in advance guys.
Edit:
Here is the HTML Code. I put asterisks for sensitive info. The asterisked info is what I need to pull. I only posted the first quarter or so of the code because it's too many characters but the code just repeats for more rows.
<HTML>
<HEAD>
<TITLE>***************</TITLE>
<SCRIPT LANGUAGE="JavaScript">
function to_SchedForm(theForm) {
var j = 0;
if (theForm.p_chkbox_cnt.value == 1)
{
if (theForm.p_part_chkbox.checked ){
++j;
}
}
else{
for (var i = 0; i < theForm.p_part_chkbox.length; i++ ) {
if (theForm.p_part_chkbox[i].checked ){
++j;
}
}
}
if (j == 0) {
alert("No Part Numbers Selected");
return false;
}
return true;
}
function to_MultiSchedForm(theForm) {
var j = 0;
var c = 0;
var k = 0;
for (var i = 0; i < theForm.p_part_chkbox.length; i++ ) {
if (theForm.p_part_chkbox[i].checked ){++k;
if (theForm.p_mode_chk[i].value != "CR"){
++j;
}
}
}
if (k == 0) {
alert("No Part Numbers Selected")
return false;
}
if (j != 0 && theForm.ACTION1.value == "multi_order") {
alert("The Multiple Schedule Update option is only available for Schedules that currently have a blank Last Commit value. Use the Individual Schedules Button to change a commitment Date.")
return false;
}
return true;
}
</SCRIPT>
</HEAD>
<BODY>
<TABLE BORDER="0" WIDTH="100%"
CELLSPACING="0" CELLPADDING="0">
<TR>
<TD WIDTH="100%", VALIGN="top"><IMG SRC="/apps/space/img/PPPS_NEW.jpg" ALT="GM Banner" NAME="PPPS1"></TD>
</TR>
<TR>
<TD width="50%"><HR></TD>
</TR>
</TABLE>
<TABLE BORDER="0" WIDTH="100%" CELLSPACING="0"
CELLPADDING="0">
<TR>
<TD WIDTH="100%", VALIGN="top", ALIGN="center"><IMG SRC="/apps/space/img/priority3.jpg" ALT="Priority Banner" NAME="Priority1"></TD>
</TR>
</TABLE>
<BR>
<CENTER>
<TABLE WIDTH="100%">
<TR>
<FORM ACTION="Schedule.PrioritySummary" METHOD="POST" NAME="to1_PS_Page">
<INPUT TYPE="hidden" NAME="P_PERSON_ID" VALUE="BZRGJH">
<INPUT TYPE="hidden" NAME="p_mode" VALUE="EDIT">
<INPUT TYPE="hidden" NAME="p_type" VALUE="SCHEDULE">
<INPUT TYPE="hidden" NAME="p_space_duns" VALUE="">
<INPUT TYPE="hidden" NAME="p_onum" VALUE="">
<INPUT TYPE="hidden" NAME="p_proc" VALUE="">
<INPUT TYPE="hidden" NAME="p_zcode" VALUE="BL62">
<INPUT TYPE="hidden" NAME="c_sort_one" VALUE="part_number">
<INPUT TYPE="hidden" NAME="c_sort_two" VALUE="priority">
<INPUT TYPE="hidden" NAME="c_sort_three" VALUE="commit_mode">
<INPUT TYPE="hidden" NAME="c_sort_four" VALUE="po_rel_sort">
<INPUT TYPE="hidden" NAME="p_supplier" VALUE="">
<INPUT TYPE="hidden" NAME="p_zcodes_space" VALUE="">
<INPUT TYPE="hidden" NAME="p_duns" VALUE="">
<INPUT TYPE="hidden" NAME="p_part" VALUE="">
<INPUT TYPE="hidden" NAME="p_sort_type" VALUE="none">
<TD VALIGN="BOTTOM" ALIGN="LEFT"><FONT FACE="courierNew" SIZE="2"><B> Part #:</B><INPUT TYPE="text" NAME="p_pnum" SIZE="12" MAXLENGTH="12"></FONT><INPUT TYPE="submit" VALUE="GO"></TD>
</FORM>
<FORM ACTION="Schedule.PrioritySummary" METHOD="POST" NAME="to2_PS_Page">
<INPUT TYPE="hidden" NAME="P_PERSON_ID" VALUE="BZRGJH">
<INPUT TYPE="hidden" NAME="p_mode" VALUE="EDIT">
<INPUT TYPE="hidden" NAME="p_type" VALUE="SCHEDULE">
<INPUT TYPE="hidden" NAME="p_space_duns" VALUE="">
<INPUT TYPE="hidden" NAME="p_pnum" VALUE="">
<INPUT TYPE="hidden" NAME="p_proc" VALUE="">
<INPUT TYPE="hidden" NAME="p_zcode" VALUE="BL62">
<INPUT TYPE="hidden" NAME="c_sort_one" VALUE="po_rel_sort">
<INPUT TYPE="hidden" NAME="c_sort_two" VALUE="part_number">
<INPUT TYPE="hidden" NAME="c_sort_three" VALUE="priority">
<INPUT TYPE="hidden" NAME="c_sort_four" VALUE="commit_mode">
<INPUT TYPE="hidden" NAME="p_sort_type" VALUE="none">
<INPUT TYPE="hidden" NAME="p_supplier" VALUE="">
<INPUT TYPE="hidden" NAME="p_zcodes_space" VALUE="">
<INPUT TYPE="hidden" NAME="p_duns" VALUE="">
<INPUT TYPE="hidden" NAME="p_part" VALUE="">
<TD VALIGN="BOTTOM" ALIGN="LEFT"><FONT FACE="courierNew" SIZE="2"><B> Order #: </B><INPUT TYPE="text" NAME="p_onum" SIZE="12" MAXLENGTH="12"></FONT><INPUT TYPE="submit" VALUE="GO"></TD>
</FORM>
<FORM ACTION="Schedule.PrioritySummary" METHOD="POST" NAME="to3_PS_Page">
<INPUT TYPE="hidden" NAME="P_PERSON_ID" VALUE="BZRGJH">
<INPUT TYPE="hidden" NAME="p_mode" VALUE="EDIT">
<INPUT TYPE="hidden" NAME="p_type" VALUE="SCHEDULE">
<INPUT TYPE="hidden" NAME="p_space_duns" VALUE="">
<INPUT TYPE="hidden" NAME="p_pnum" VALUE="">
<INPUT TYPE="hidden" NAME="p_onum" VALUE="">
<INPUT TYPE="hidden" NAME="p_zcode" VALUE="BL62">
<INPUT TYPE="hidden" NAME="c_sort_one" VALUE="po_rel_sort">
<INPUT TYPE="hidden" NAME="c_sort_two" VALUE="part_number">
<INPUT TYPE="hidden" NAME="c_sort_three" VALUE="priority">
<INPUT TYPE="hidden" NAME="c_sort_four" VALUE="commit_mode">
<INPUT TYPE="hidden" NAME="p_sort_type" VALUE="none">
<INPUT TYPE="hidden" NAME="p_supplier" VALUE="">
<INPUT TYPE="hidden" NAME="p_zcodes_space" VALUE="">
<INPUT TYPE="hidden" NAME="p_duns" VALUE="">
<INPUT TYPE="hidden" NAME="p_part" VALUE="">
<TD VALIGN="BOTTOM" ALIGN="LEFT"><FONT FACE="courierNew" SIZE="2"><B><SELECT NAME="p_proc"><OPTION VALUE="0">< Select Processor ><OPTION VALUE="KXH">K.Hr 918040497243 <OPTION VALUE="SJF">S. Fox 586-484-0855 </SELECT></B></FONT><INPUT TYPE="submit" VALUE="GO"></TD>
</FORM>
</TR>
</TABLE>
</CENTER>
<HR>
<CENTER>
<FONT FACE="courierNew" SIZE="2">Mfg. DUNS: <B>178522926</B></FONT>
<FONT FACE="courierNew" SIZE="2"><B>KAUTEX INC</B></FONT>
<FONT FACE="courierNew" SIZE="2">Z-code: <B>BL62</B></FONT>
</CENTER>
<CENTER>
<TABLE WIDTH="100%" BORDER="2" BORDERCOLOR="#00008B">
<TR>
<TH VALIGN="CENTER" ALIGN="CENTER" WIDTH="5%" BGCOLOR="darkblue"><CENTER><FONT COLOR="WHITE" SIZE="-1"><B><FONT FACE="courierNew" SIZE="2">Select One or More</FONT></B></FONT></CENTER></TH><FORM ACTION="Schedule.PrioritySummary" METHOD="POST" NAME="to4_PS_Page">
<INPUT TYPE="hidden" NAME="P_PERSON_ID" VALUE="BZRGJH">
<INPUT TYPE="hidden" NAME="iv_group" VALUE="">
<INPUT TYPE="hidden" NAME="p_mode" VALUE="EDIT">
<INPUT TYPE="hidden" NAME="p_type" VALUE="SCHEDULE">
<INPUT TYPE="hidden" NAME="p_space_duns" VALUE="">
<INPUT TYPE="hidden" NAME="p_duns_number" VALUE="">
<INPUT TYPE="hidden" NAME="p_zcode" VALUE="BL62">
<INPUT TYPE="hidden" NAME="p_pnum" VALUE="">
<INPUT TYPE="hidden" NAME="p_onum" VALUE="">
<INPUT TYPE="hidden" NAME="p_proc" VALUE="">
<INPUT TYPE="hidden" NAME="p_sort_type" VALUE="part_num">
<INPUT TYPE="hidden" NAME="c_sort_one" VALUE="part_number">
<INPUT TYPE="hidden" NAME="c_sort_two" VALUE="priority">
<INPUT TYPE="hidden" NAME="c_sort_three" VALUE="commit_mode">
<INPUT TYPE="hidden" NAME="c_sort_four" VALUE="po_rel_sort">
<INPUT TYPE="hidden" NAME="p_supplier" VALUE="">
<INPUT TYPE="hidden" NAME="p_zcodes_space" VALUE="">
<INPUT TYPE="hidden" NAME="p_duns" VALUE="">
<INPUT TYPE="hidden" NAME="p_part" VALUE="">
<TH BGCOLOR="darkblue"><CENTER><FONT COLOR="WHITE" SIZE="-1"><B><INPUT TYPE="image" NAME="p_img" SRC="/apps/space/img/Part_Number_Button2.gif" border="0"></B></FONT></CENTER></TH></FORM>
<TH VALIGN="CENTER" ALIGN="CENTER" WIDTH="21%" BGCOLOR="darkblue"><CENTER><FONT COLOR="WHITE" SIZE="-1"><B><FONT FACE="courierNew" SIZE="2">Description</FONT></B></FONT></CENTER></TH><FORM ACTION="Schedule.PrioritySummary" METHOD="POST" NAME="to5_PS_Page">
<INPUT TYPE="hidden" NAME="P_PERSON_ID" VALUE="BZRGJH">
<INPUT TYPE="hidden" NAME="iv_group" VALUE="">
<INPUT TYPE="hidden" NAME="p_mode" VALUE="EDIT">
<INPUT TYPE="hidden" NAME="p_type" VALUE="SCHEDULE">
<INPUT TYPE="hidden" NAME="p_space_duns" VALUE="">
<INPUT TYPE="hidden" NAME="p_duns_number" VALUE="">
<INPUT TYPE="hidden" NAME="p_zcode" VALUE="BL62">
<INPUT TYPE="hidden" NAME="p_pnum" VALUE="">
<INPUT TYPE="hidden" NAME="p_onum" VALUE="">
<INPUT TYPE="hidden" NAME="p_proc" VALUE="">
<INPUT TYPE="hidden" NAME="p_sort_type" VALUE="ordr_num">
<INPUT TYPE="hidden" NAME="c_sort_one" VALUE="po_rel_sort">
<INPUT TYPE="hidden" NAME="c_sort_two" VALUE="part_number">
<INPUT TYPE="hidden" NAME="c_sort_three" VALUE="priority">
<INPUT TYPE="hidden" NAME="c_sort_four" VALUE="commit_mode">
<INPUT TYPE="hidden" NAME="p_supplier" VALUE="">
<INPUT TYPE="hidden" NAME="p_zcodes_space" VALUE="">
<INPUT TYPE="hidden" NAME="p_duns" VALUE="">
<INPUT TYPE="hidden" NAME="p_part" VALUE="">
<TH BGCOLOR="darkblue"><CENTER><FONT COLOR="WHITE" SIZE="-1"><B><INPUT TYPE="image" NAME="p_img" SRC="/apps/space/img/Order_Number_Button2.gif" border="0"></B></FONT></CENTER></TH></FORM>
<TH VALIGN="CENTER" ALIGN="CENTER" WIDTH="7%" BGCOLOR="darkblue"><CENTER><FONT COLOR="WHITE" SIZE="-1"><B><FONT FACE="courierNew" SIZE="2">Last Commit</FONT></B></FONT></CENTER></TH><FORM ACTION="Schedule.PrioritySummary" METHOD="POST" NAME="to6_PS_Page">
<INPUT TYPE="hidden" NAME="P_PERSON_ID" VALUE="BZRGJH">
<INPUT TYPE="hidden" NAME="iv_group" VALUE="">
<INPUT TYPE="hidden" NAME="p_mode" VALUE="EDIT">
<INPUT TYPE="hidden" NAME="p_type" VALUE="SCHEDULE">
<INPUT TYPE="hidden" NAME="p_space_duns" VALUE="">
<INPUT TYPE="hidden" NAME="p_duns_number" VALUE="">
<INPUT TYPE="hidden" NAME="p_zcode" VALUE="BL62">
<INPUT TYPE="hidden" NAME="p_pnum" VALUE="">
<INPUT TYPE="hidden" NAME="p_onum" VALUE="">
<INPUT TYPE="hidden" NAME="p_proc" VALUE="">
<INPUT TYPE="hidden" NAME="p_sort_type" VALUE="none">
<INPUT TYPE="hidden" NAME="p_supplier" VALUE="">
<INPUT TYPE="hidden" NAME="p_zcodes_space" VALUE="">
<INPUT TYPE="hidden" NAME="p_duns" VALUE="">
<INPUT TYPE="hidden" NAME="p_part" VALUE="">
<TH BGCOLOR="darkblue"><CENTER><FONT COLOR="WHITE" SIZE="-1"><B><INPUT TYPE="image" NAME="p_img" SRC="/apps/space/img/Due_Now_Button2.gif" border="0"></B></FONT></CENTER></TH></FORM>
<TH VALIGN="CENTER" ALIGN="CENTER" WIDTH="5%" BGCOLOR="darkblue"><CENTER><FONT COLOR="WHITE" SIZE="-1"><B><FONT FACE="courierNew" SIZE="2">Due 11/03</FONT></B></FONT></CENTER></TH><TH VALIGN="CENTER" ALIGN="CENTER" WIDTH="5%" BGCOLOR="darkblue"><CENTER><FONT COLOR="WHITE" SIZE="-1"><B><FONT FACE="courierNew" SIZE="2">Due 11/10</FONT></B></FONT></CENTER></TH><TH VALIGN="CENTER" ALIGN="CENTER" WIDTH="5%" BGCOLOR="darkblue"><CENTER><FONT COLOR="WHITE" SIZE="-1"><B><FONT FACE="courierNew" SIZE="2">Due 11/17</FONT></B></FONT></CENTER></TH><TH VALIGN="CENTER" ALIGN="CENTER" WIDTH="5%" BGCOLOR="darkblue"><CENTER><FONT COLOR="WHITE" SIZE="-1"><B><FONT FACE="courierNew" SIZE="2">Due 11/24</FONT></B></FONT></CENTER></TH><TH VALIGN="CENTER" ALIGN="CENTER" WIDTH="5%" BGCOLOR="darkblue"><CENTER><FONT COLOR="WHITE" SIZE="-1"><B><FONT FACE="courierNew" SIZE="2">Future</FONT></B></FONT></CENTER></TH><TH VALIGN="CENTER" ALIGN="CENTER" WIDTH="5%" BGCOLOR="darkblue"><CENTER><FONT COLOR="WHITE" SIZE="-1"><B><FONT FACE="courierNew" SIZE="2">Total</FONT></B></FONT></CENTER></TH><TH VALIGN="CENTER" ALIGN="CENTER" WIDTH="5%" BGCOLOR="darkblue"><CENTER><FONT COLOR="WHITE" SIZE="-1"><B><FONT FACE="courierNew" SIZE="2">SNR</FONT></B></FONT></CENTER></TH></TR>
<FORM ACTION="Schedule.SchedForm" METHOD="POST" NAME="toSchedForm"onSubmit="if (this.ACTION1.value == 'single_order')
{
if (to_SchedForm(this))
{
return true
}
else
{
return false
}
}
else
{
if (to_MultiSchedForm(this))
{
document.toSchedForm.action="Schedule.multi_schedform";return true
}
else
{
return false
}
return false
}">
<INPUT TYPE="hidden" NAME="P_EMS_DIVISION" VALUE="M ">
<INPUT TYPE="hidden" NAME="P_DOC_PREFIX" VALUE="XQ">
<INPUT TYPE="hidden" NAME="P_DOC_NUMBER" VALUE="APHL ">
<INPUT TYPE="hidden" NAME="P_DOCUMENT_TYPE" VALUE="Q">
<INPUT TYPE="hidden" NAME="P_PART_DLS" VALUE="A">
<INPUT TYPE="hidden" NAME="P_PART_PLS" VALUE=" ">
<INPUT TYPE="hidden" NAME="P_PART_NUM" VALUE="23214821">
<INPUT TYPE="hidden" NAME="p_mode_chk" VALUE="CR">
<INPUT TYPE="hidden" NAME="p_chkbox_cnt" VALUE="1">
<TR>
<TD VALIGN="CENTER" ALIGN="CENTER"><B><INPUT TYPE="checkbox" NAME="p_part_chkbox" VALUE="1"></B></TD>
<TD VALIGN="CENTER"
ALIGN="RIGHT"><FONT FACE="CourierNew" SIZE="2"><B>******** </B></FONT></TD>
<TD VALIGN="CENTER"
ALIGN="LEFT"><FONT FACE="courierNew" SIZE="2">TANK ASM - FUEL </FONT></TD>
<TD><FONT FACE="CourierNew" SIZE="2">*******</FONT></TD>
<TD VALIGN="CENTER"
ALIGN="CENTER"><FONT FACE="courierNew" SIZE="2"><B>-</B></FONT></TD>
<TD VALIGN="CENTER"
ALIGN="CENTER"><B><FONT COLOR="*****" FACE="courierNew" SIZE="2"></B><B>12</B></FONT></TD>
<TD VALIGN="CENTER"
ALIGN="CENTER"><FONT FACE="courierNew" SIZE="2"><B>0</B></FONT></TD>
<TD VALIGN="CENTER"
ALIGN="CENTER"><FONT FACE="courierNew" SIZE="2"><B>0</B></FONT></TD>
<TD VALIGN="CENTER"
ALIGN="CENTER"><FONT FACE="courierNew" SIZE="2"><B>0</B></FONT></TD>
<TD VALIGN="CENTER"
ALIGN="CENTER"><FONT FACE="courierNew" SIZE="2"><B>0</B></FONT></TD>
<TD VALIGN="CENTER"
ALIGN="CENTER"><FONT FACE="courierNew" SIZE="2"><B>0</B></FONT></TD>
<TD VALIGN="CENTER"
ALIGN="CENTER"><FONT FACE="courierNew" SIZE="2"><B>****</B></FONT></TD>
<TD VALIGN="CENTER"
ALIGN="CENTER"><FONT FACE="courierNew" SIZE="2"><B>-</B></FONT></TD>
</TR>
<INPUT TYPE="hidden" NAME="P_EMS_DIVISION" VALUE="M ">
<INPUT TYPE="hidden" NAME="P_DOC_PREFIX" VALUE="XQ">
<INPUT TYPE="hidden" NAME="P_DOC_NUMBER" VALUE="APHL ">
<INPUT TYPE="hidden" NAME="P_DOCUMENT_TYPE" VALUE="Q">
<INPUT TYPE="hidden" NAME="P_PART_DLS" VALUE="A">
<INPUT TYPE="hidden" NAME="P_PART_PLS" VALUE=" ">
<INPUT TYPE="hidden" NAME="P_PART_NUM" VALUE="***********">
<INPUT TYPE="hidden" NAME="p_mode_chk" VALUE="CR">
<INPUT TYPE="hidden" NAME="p_chkbox_cnt" VALUE="2">
<TR>
<TD VALIGN="CENTER" ALIGN="CENTER"><B><INPUT TYPE="checkbox" NAME="p_part_chkbox" VALUE="2"></B></TD>
<TD VALIGN="CENTER"
ALIGN="RIGHT"><FONT FACE="CourierNew" SIZE="2"><B>******** </B></FONT></TD>
<TD VALIGN="CENTER"
ALIGN="LEFT"><FONT FACE="courierNew" SIZE="2">TANK ASM - FUEL </FONT></TD>
<TD><FONT FACE="CourierNew" SIZE="2">J1UJ3 -000</FONT></TD>
<TD VALIGN="CENTER"
ALIGN="CENTER"><FONT FACE="courierNew" SIZE="2"><B>-</B></FONT></TD>
<TD VALIGN="CENTER"
ALIGN="CENTER"><B><FONT COLOR="FF0000" FACE="courierNew" SIZE="2"></B><B>*****</B></FONT></TD>
<TD VALIGN="CENTER"
ALIGN="CENTER"><FONT FACE="courierNew" SIZE="2"><B>0</B></FONT></TD>
<TD VALIGN="CENTER"
ALIGN="CENTER"><FONT FACE="courierNew" SIZE="2"><B>0</B></FONT></TD>
<TD VALIGN="CENTER"
ALIGN="CENTER"><FONT FACE="courierNew" SIZE="2"><B>0</B></FONT></TD>
<TD VALIGN="CENTER"
ALIGN="CENTER"><FONT FACE="courierNew" SIZE="2"><B>0</B></FONT></TD>
<TD VALIGN="CENTER"
ALIGN="CENTER"><FONT FACE="courierNew" SIZE="2"><B>0</B></FONT></TD>
<TD VALIGN="CENTER"
ALIGN="CENTER"><FONT FACE="courierNew" SIZE="2"><B>********</B></FONT></TD>
<TD VALIGN="CENTER"
ALIGN="CENTER"><FONT FACE="courierNew" SIZE="2"><B>-</B></FONT></TD>

Okay, so its useful to know that you can find any element by its element id, e.g. driver.findElement(By.id("table")). This will give you the first element of that type. However, you have multiple tables, so you'll need to find a way to get the right table.
There are different ways to do this, but they'll usually revolve around some individual characteristic of your target. In this case the obvious example for me is that it contains this:
<TR>
<TD WIDTH="100%", VALIGN="top", ALIGN="center"><IMG SRC="/apps/space/img/priority3.jpg" ALT="Priority Banner" NAME="Priority1"></TD>
</TR>
Though this means we're looking down into children levels (makes things a little more complicated). What we can do is look for that particular element and then find its parent table via xpath like in this xpath tutorial.
So, to find the image element we simply use:
WebElement imageElement = driver.findElement(By.name("Priority1"));
This gives us the image element.
To find the table containing said imageElement we then use:
WebElement tableElement = imageElement.findElement(By.xpath(//ancestor::table));
This should find the ancestor element that is a table containing the priority1 image.
I suggest you have a look at how x-path works. Its very useful, but sometimes it does require a little tinkering (especially if a web page changes).

Related

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>

Unexpected Exception caught setting on class xxx: Error setting expression 'xxx' with value ['x', ] [duplicate]

I am trying to submit unknown number input from HTML Form to Action class and fetch the Input parameter information by using request Method(Used ServletActionContext) in the Action class.
But its throwing
Unexpected Exception caught setting 'xx' on 'class classname Error setting expression 'xx' with value ['yy', ]
Since input elements in the form are adding dynamically using JS, i am not in the position to have getters and setters in the Action class.
How to process the Action class without any exceptions?
JSP:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Team Activity Log</title>
<SCRIPT language="javascript">
function addRow(tableid)
{
var table = document.getElementById(tableid);
var rowCount = table.rows.length;
var row = table.insertRow(rowCount);
var cell1 = row.insertCell(0);
var element1 = document.createElement("select");
element1=document.getElementById("sele").cloneNode(true);
element1.type="select";
cell1.appendChild(element1);
var cell2=row.insertCell(1);
var element2 = document.createElement("input");
element2.type="text";
element2.setAttribute("placeholder","E.g:1234");
cell2.appendChild(element2);
var cell3=row.insertCell(2);
var element3 = document.createElement("input");
element3.type="text";
element3.setAttribute("placeholder","Brief your work");
cell3.appendChild(element3);
var cell4=row.insertCell(3);
var element4 = document.createElement("input");
element4.type="text";
element4.setAttribute("placeholder","MM min");
cell4.appendChild(element4);
var cell5=row.insertCell(4);
var element5 = document.createElement("img");
element5.src="close.png";
element5.setAttribute("id","delete");
element5.setAttribute("onclick","changeImage(this)");
cell5.appendChild(element5);
}
function changeImage(temp)
{
(temp.parentElement).parentElement.remove();
}
function convert(tableid,temp2)
{
var table=document.getElementById(tableid);
console.log(table.rows.length);
var hidelement=document.getElementById(temp2);
hidelement.setAttribute("value",table.rows.length-1);
for(var i=1;i<table.rows.length;i++)
{
var tt="tt"+i;
var rf="rf"+i;
var des="des"+i;
var eff="eff"+i;
console.log("executing function");
var elemen=table.rows[i].cells[0].querySelector("*");
elemen.setAttribute("name",tt);
elemen=table.rows[i].cells[1].querySelector("*");
elemen.setAttribute("name",rf);
elemen=table.rows[i].cells[2].querySelector("*");
elemen.setAttribute("name",des);
elemen=table.rows[i].cells[3].querySelector("*");
elemen.setAttribute("name",eff);
}
}
</script>
</head>
<body>
<INPUT type="button" value="Add Row" onclick="addRow('matrix')" />
<%# taglib uri="/struts-tags" prefix="s" %>
<s:url id="myActionUrl" action="timesheetprocess" />
<form action=<s:property value="%{myActionUrl}" />>
<input type="hidden" id="taskcount" value="5">
<table id="matrix">
<tr>
<th>Task Type</th>
<th>Reference ID</th>
<th>Description</th>
<th>Efforts</th>
<th></th>
</tr>
<tr>
<td>
<select id="sele">
<option value="" disabled selected>Select your option</option>
<option value="SR">SR</option>
<option value="CR">CR</option>
<option value="ALM">ALM</option>
<option value="INCIDENT">INCIDENT</option>
<option value="OTHER">OTHER</option>
</select></TD>
<td>
<INPUT type="text" placeholder="E.g:1234"/>
</td>
<td>
<INPUT type="text" placeholder="Brief your work"/>
</td>
<td>
<INPUT type="text" placeholder="MM min" />
</td>
<td>
<img id="delete" src="close.png" onclick="changeImage(this)">
</td>
</tr><tr>
<td>
<select id="sele">
<option value="" disabled selected>Select your option</option>
<option value="SR">SR</option>
<option value="CR">CR</option>
<option value="ALM">ALM</option>
<option value="INCIDENT">INCIDENT</option>
<option value="OTHER">OTHER</option>
</select></TD>
<td>
<INPUT type="text" placeholder="E.g:1234"/>
</td>
<td>
<INPUT type="text" placeholder="Brief your work"/>
</td>
<td>
<INPUT type="text" placeholder="MM min" />
</td>
<td>
<img id="delete" src="close.png" onclick="changeImage(this)">
</td>
</tr>
<tr>
<td>
<select id="sele">
<option value="" disabled selected>Select your option</option>
<option value="SR">SR</option>
<option value="CR">CR</option>
<option value="ALM">ALM</option>
<option value="INCIDENT">INCIDENT</option>
<option value="OTHER">OTHER</option>
</select></TD>
<td>
<INPUT type="text" placeholder="E.g:1234"/>
</td>
<td>
<INPUT type="text" placeholder="Brief your work"/>
</td>
<td>
<INPUT type="text" placeholder="MM min" />
</td>
<td>
<img id="delete" src="close.png" onclick="changeImage(this)">
</td>
</tr>
<tr>
<td>
<select id="sele">
<option value="" disabled selected>Select your option</option>
<option value="SR">SR</option>
<option value="CR">CR</option>
<option value="ALM">ALM</option>
<option value="INCIDENT">INCIDENT</option>
<option value="OTHER">OTHER</option>
</select></TD>
<td>
<INPUT type="text" placeholder="E.g:1234"/>
</td>
<td>
<INPUT type="text" placeholder="Brief your work"/>
</td>
<td>
<INPUT type="text" placeholder="MM min" />
</td>
<td>
<img id="delete" src="close.png" onclick="changeImage(this)">
</td>
</tr>
<tr>
<td>
<select id="sele">
<option value="" disabled selected>Select your option</option>
<option value="SR">SR</option>
<option value="CR">CR</option>
<option value="ALM">ALM</option>
<option value="INCIDENT">INCIDENT</option>
<option value="OTHER">OTHER</option>
</select></TD>
<td>
<INPUT type="text" placeholder="E.g:1234"/>
</td>
<td>
<INPUT type="text" placeholder="Brief your work"/>
</td>
<td>
<INPUT type="text" placeholder="MM min" />
</td>
<td>
<img id="delete" src="close.png" onclick="changeImage(this)">
</td>
</tr>
</table>
<INPUT type="button" value="Submit" onclick="convert('matrix','taskcount')" />
</form>
</body>
</html>
Action tag in struts.xml
<action name="timesheetprocess" class="com.App.Controller.Timesheet.Timeprocess"
method="execute">
<result name="success">Time.jsp</result>
</action>
My Action class:
import javax.servlet.http.HttpServletRequest;
import org.apache.struts2.ServletActionContext;
public class Timeprocess {
public String execute() {
HttpServletRequest request = ServletActionContext.getRequest();
String tt="tt";
String rf="rf";
String des="des";
String eff="eff";
for(int i=0;i<Integer.parseInt(request.getParameter("taskcount"));i++)
{
System.out.println("Task Type :"+ request.getParameter(tt+String.valueOf(i)));
System.out.println("Task Type :"+ request.getParameter(rf+String.valueOf(i)));
System.out.println("Task Type :"+ request.getParameter(des+String.valueOf(i)));
System.out.println("Task Type :"+ request.getParameter(eff+String.valueOf(i)));
}
return "success";
}
}
You can control the process of parameters population by Struts2 via overriding interceptors in the action config.
<action name="timesheetprocess" class="com.App.Controller.Timesheet.Timeprocess"
method="execute">
<interceptor-ref name="defaultStack">
<param name="params.excludeParams">.*</param>
</interceptor-ref>
<result name="success">Time.jsp</result>
</action>
There you modify the excludeParams property of the params interceptor to exclude all parameters from processing via OGNL.
You should not get any exception in this way, but make sure you have configured struts.devMode=false
<constant name="struts.devMode" value="false" />
It should remove unnecessary warnings from the output. If you still get any warnings or exceptions in the log, then you should configure your logging framework to suppress those warnings or errors from the output.

Struts 2 - Unexpected Exception caught setting 'xx'

I am trying to submit unknown number input from HTML Form to Action class and fetch the Input parameter information by using request Method(Used ServletActionContext) in the Action class.
But its throwing
Unexpected Exception caught setting 'xx' on 'class classname Error setting expression 'xx' with value ['yy', ]
Since input elements in the form are adding dynamically using JS, i am not in the position to have getters and setters in the Action class.
How to process the Action class without any exceptions?
JSP:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Team Activity Log</title>
<SCRIPT language="javascript">
function addRow(tableid)
{
var table = document.getElementById(tableid);
var rowCount = table.rows.length;
var row = table.insertRow(rowCount);
var cell1 = row.insertCell(0);
var element1 = document.createElement("select");
element1=document.getElementById("sele").cloneNode(true);
element1.type="select";
cell1.appendChild(element1);
var cell2=row.insertCell(1);
var element2 = document.createElement("input");
element2.type="text";
element2.setAttribute("placeholder","E.g:1234");
cell2.appendChild(element2);
var cell3=row.insertCell(2);
var element3 = document.createElement("input");
element3.type="text";
element3.setAttribute("placeholder","Brief your work");
cell3.appendChild(element3);
var cell4=row.insertCell(3);
var element4 = document.createElement("input");
element4.type="text";
element4.setAttribute("placeholder","MM min");
cell4.appendChild(element4);
var cell5=row.insertCell(4);
var element5 = document.createElement("img");
element5.src="close.png";
element5.setAttribute("id","delete");
element5.setAttribute("onclick","changeImage(this)");
cell5.appendChild(element5);
}
function changeImage(temp)
{
(temp.parentElement).parentElement.remove();
}
function convert(tableid,temp2)
{
var table=document.getElementById(tableid);
console.log(table.rows.length);
var hidelement=document.getElementById(temp2);
hidelement.setAttribute("value",table.rows.length-1);
for(var i=1;i<table.rows.length;i++)
{
var tt="tt"+i;
var rf="rf"+i;
var des="des"+i;
var eff="eff"+i;
console.log("executing function");
var elemen=table.rows[i].cells[0].querySelector("*");
elemen.setAttribute("name",tt);
elemen=table.rows[i].cells[1].querySelector("*");
elemen.setAttribute("name",rf);
elemen=table.rows[i].cells[2].querySelector("*");
elemen.setAttribute("name",des);
elemen=table.rows[i].cells[3].querySelector("*");
elemen.setAttribute("name",eff);
}
}
</script>
</head>
<body>
<INPUT type="button" value="Add Row" onclick="addRow('matrix')" />
<%# taglib uri="/struts-tags" prefix="s" %>
<s:url id="myActionUrl" action="timesheetprocess" />
<form action=<s:property value="%{myActionUrl}" />>
<input type="hidden" id="taskcount" value="5">
<table id="matrix">
<tr>
<th>Task Type</th>
<th>Reference ID</th>
<th>Description</th>
<th>Efforts</th>
<th></th>
</tr>
<tr>
<td>
<select id="sele">
<option value="" disabled selected>Select your option</option>
<option value="SR">SR</option>
<option value="CR">CR</option>
<option value="ALM">ALM</option>
<option value="INCIDENT">INCIDENT</option>
<option value="OTHER">OTHER</option>
</select></TD>
<td>
<INPUT type="text" placeholder="E.g:1234"/>
</td>
<td>
<INPUT type="text" placeholder="Brief your work"/>
</td>
<td>
<INPUT type="text" placeholder="MM min" />
</td>
<td>
<img id="delete" src="close.png" onclick="changeImage(this)">
</td>
</tr><tr>
<td>
<select id="sele">
<option value="" disabled selected>Select your option</option>
<option value="SR">SR</option>
<option value="CR">CR</option>
<option value="ALM">ALM</option>
<option value="INCIDENT">INCIDENT</option>
<option value="OTHER">OTHER</option>
</select></TD>
<td>
<INPUT type="text" placeholder="E.g:1234"/>
</td>
<td>
<INPUT type="text" placeholder="Brief your work"/>
</td>
<td>
<INPUT type="text" placeholder="MM min" />
</td>
<td>
<img id="delete" src="close.png" onclick="changeImage(this)">
</td>
</tr>
<tr>
<td>
<select id="sele">
<option value="" disabled selected>Select your option</option>
<option value="SR">SR</option>
<option value="CR">CR</option>
<option value="ALM">ALM</option>
<option value="INCIDENT">INCIDENT</option>
<option value="OTHER">OTHER</option>
</select></TD>
<td>
<INPUT type="text" placeholder="E.g:1234"/>
</td>
<td>
<INPUT type="text" placeholder="Brief your work"/>
</td>
<td>
<INPUT type="text" placeholder="MM min" />
</td>
<td>
<img id="delete" src="close.png" onclick="changeImage(this)">
</td>
</tr>
<tr>
<td>
<select id="sele">
<option value="" disabled selected>Select your option</option>
<option value="SR">SR</option>
<option value="CR">CR</option>
<option value="ALM">ALM</option>
<option value="INCIDENT">INCIDENT</option>
<option value="OTHER">OTHER</option>
</select></TD>
<td>
<INPUT type="text" placeholder="E.g:1234"/>
</td>
<td>
<INPUT type="text" placeholder="Brief your work"/>
</td>
<td>
<INPUT type="text" placeholder="MM min" />
</td>
<td>
<img id="delete" src="close.png" onclick="changeImage(this)">
</td>
</tr>
<tr>
<td>
<select id="sele">
<option value="" disabled selected>Select your option</option>
<option value="SR">SR</option>
<option value="CR">CR</option>
<option value="ALM">ALM</option>
<option value="INCIDENT">INCIDENT</option>
<option value="OTHER">OTHER</option>
</select></TD>
<td>
<INPUT type="text" placeholder="E.g:1234"/>
</td>
<td>
<INPUT type="text" placeholder="Brief your work"/>
</td>
<td>
<INPUT type="text" placeholder="MM min" />
</td>
<td>
<img id="delete" src="close.png" onclick="changeImage(this)">
</td>
</tr>
</table>
<INPUT type="button" value="Submit" onclick="convert('matrix','taskcount')" />
</form>
</body>
</html>
Action tag in struts.xml
<action name="timesheetprocess" class="com.App.Controller.Timesheet.Timeprocess"
method="execute">
<result name="success">Time.jsp</result>
</action>
My Action class:
import javax.servlet.http.HttpServletRequest;
import org.apache.struts2.ServletActionContext;
public class Timeprocess {
public String execute() {
HttpServletRequest request = ServletActionContext.getRequest();
String tt="tt";
String rf="rf";
String des="des";
String eff="eff";
for(int i=0;i<Integer.parseInt(request.getParameter("taskcount"));i++)
{
System.out.println("Task Type :"+ request.getParameter(tt+String.valueOf(i)));
System.out.println("Task Type :"+ request.getParameter(rf+String.valueOf(i)));
System.out.println("Task Type :"+ request.getParameter(des+String.valueOf(i)));
System.out.println("Task Type :"+ request.getParameter(eff+String.valueOf(i)));
}
return "success";
}
}
You can control the process of parameters population by Struts2 via overriding interceptors in the action config.
<action name="timesheetprocess" class="com.App.Controller.Timesheet.Timeprocess"
method="execute">
<interceptor-ref name="defaultStack">
<param name="params.excludeParams">.*</param>
</interceptor-ref>
<result name="success">Time.jsp</result>
</action>
There you modify the excludeParams property of the params interceptor to exclude all parameters from processing via OGNL.
You should not get any exception in this way, but make sure you have configured struts.devMode=false
<constant name="struts.devMode" value="false" />
It should remove unnecessary warnings from the output. If you still get any warnings or exceptions in the log, then you should configure your logging framework to suppress those warnings or errors from the output.

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