When a checkbox is selected in a JSP, multiple data for that record is fetched and then uploaded to the action class for background processing *.hbm.xml in the case of a double primary key

Source: Internet
Author: User
Tags tagname

========== Method 1:

--------1. Select the appropriate checkbox to remove the button after the click-------------

<!--******************* Delete *******************--
<input type= "image" alt= "Delete"
Src= "<%=request.getcontextpath ()%>/images/btnimg/btn_delete.gif"
Id= "DoDelete" name= "Action:dellocationaction!delete"
class= "Button_image" onclick= "return DelCheck2 ();"/>

--------2. Code---------------for JSP pages

<table id= "datashow" align= "center" border= "1" class= "tb3" width= "100%" >
<tr class= "Gridtitle" >
&LT;TD align= "center" ><input type= "checkbox" id= "Chkall"
Name= "Chkall" onclick= "Checkboxcheck ();" ></td>
<td>aaa</td>
<td>bbb
<% String varwerks= ""; %>
<input type= "hidden" name= "Werks_n" value= "<%=varWerks%>" >
</td>
</tr>
<%//string varwerks= ""; %>
<s:iterator value= "pagebean.list" status= "index" id= "CU" >
<s:if test= "#index. Odd = True" >
<tr class= "Gridspan" >
</s:if>
<s:else>
<tr>
</s:else>
&LT;TD align= "center" >
<input type= "checkbox" id= "CB" name= "IDs" value= "<s:property value=" Lgort "/>"/>
</td>
<td><s:property value= "Lgort"/></td>
<td><s:property value= "Werks"/></td>
</tr>
</s:iterator>
</table>

-------3. Reference JS Method---------------------------------

<script src= "<%=request.getcontextpath ()%>/js/checkbox.js"
Type= "Text/javascript" ></script>

-------4. JS Method------------

function DelCheck2 ()
{
var c=checkednums ();
if (c==0)
{
Alert ("You select at least one record as the deleted object.") ");
return false;
}
if (Confirm ("Are you sure you want to delete this record?") "))
{
//-------------
var count=0;
var tb= document.all.datashow;
var str2= "";
if (tb!=null)
{
for (i=0;i<tb.rows.length;i++)
{
var var1=tb.rows[i].cells[0].children[0];
if (var1.tagname== "INPUT")
{
if (var1.type== "checkbox")
{
if (var1.checked)
{
count=count+1;
var Td1=tb.rows[i].cells[1].innertext;
var Td2=tb.rows[i].cells[2].innertext;
if (str2== "")
{
STR2=TD2;
}
Else
{
str2=str2+ "," +TD2;
}
}
}//----if (var1.type== "checkbox")------>>>>
}//---if (var1.tagname== "INPUT")------->>
}//---for (i=0;i<tb.rows.length;i++)


/* Hidden fields record the selected sequence */
Window.form1.werks_N.value = str2;
/* Normal Submission Form */
Window.form1.submit ();
}//----if (tb!=null)---->>
return true;
}
return false;
}

------------5. Code in the Action class

Explode string
Public string[] Splitstr (String s) {
string[] ss = new string[200];
Decomposition at each comma character.
SS = S.split (",");
return SS;
}

Public String Delete () throws Exception
{
HttpServletRequest request = Servletactioncontext.getrequest ();
string[] ids = request.getparametervalues ("IDs");

if (ids = = null)
{
return SUCCESS;
}
String[] Ida=request.getparametervalues ("Werks_n");
is a string to decompose slipe
System.out.println (Ida[0]);
String[] Ss=splitstr (ida[0]);

for (int i = 0; i < ids.length; i++) {
System.out.println ("Print IDs" + ids[i]);
Locationbean Locationbean = new Locationbean ();
Locationbean.setlgort (Ids[i]);

System.out.println ("Print Ida" + ss[i]);
Locationbean.setwerks (Ss[i]);
Locationservice.deletelocation (Locationbean);
}
return SUCCESS;
}

====== method 2====== (Simple) ===========

---------1. Code in a JSP page

<table id= "datashow" align= "center" border= "1" class= "tb3" width= "100%" >
<tr class= "Gridtitle" >
&LT;TD align= "center" ><input type= "checkbox" id= "Chkall" name= "Chkall" onclick= "Checkboxcheck ();" ></td>
<td>aaa</td>
<td>bbb</td>
</tr>
<s:iterator value= "pagebean.list" status= "index" id= "CU" >
<s:if test= "#index. Odd = True" >
<tr class= "Gridspan" >
</s:if>
<s:else>
<tr> </s:else>
&LT;TD align= "center" >
<input type= "checkbox" id= "CB" name= "IDs" value= "<s:property value="%{lgort + "+ werks}"/> "/>
</td>
<td><s:property value= "Lgort"/></td>
<td><s:property value= "Werks"/></td>
</tr>
</s:iterator>
</table>

-----------2. Code in the Action class

Code

---------3. *.hbm.xml in the case of double primary keys-----

<?xml version= "1.0" encoding= "UTF-8"?>
<! DOCTYPE hibernate-mapping Public "-//hibernate/hibernate mapping DTD 3.0//en"
"Http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<class name= "Com.pms.bean.base.LocationBean" table= "Tblocation" >
<composite-id>
<key-property name= "Lgort"
Column= "Lo_lgort"
Type= "Java.lang.String"/>
<key-property name= "Werks"
Column= "Lo_werks"
Type= "Java.lang.String"/>
</composite-id>
</class>

When a checkbox is selected in a JSP, multiple data for that record is fetched and then uploaded to the action class for background processing *.hbm.xml in the case of a double primary key

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.