在jsp中选中checkbox后 将该记录的多个数据获取,然后传到Action类中进行后台处理 双主键情况下 *.hbm.xml中的写法

==========方法1:

--------1. 选相应的checkbox后  点删除按钮-------------

<!-- *******************删除******************* -->
     <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.  jsp页面的代码---------------

<table id="datashow" align="center" border="1" class="tb3" width="100%">
    <tr class="gridtitle">
     <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>
     <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. 引用js方法---------------------------------

<script src="<%=request.getContextPath() %>/js/CheckBox.js"
 type="text/javascript"></script>

-------4. js方法------------

代码
function delCheck2()
{
    
var c=checkedNums();
    
if(c==0)
    {
        alert(
"您至少选择一条记录作为删除的对象。");
        
return false;
    }
    
if(confirm("您确实要删除这条记录吗?"))
    {
        
//-------------
        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++)
         
        
        
/* 隐藏域记录选中的序列 */
         window.form1.werks_N.value 
= str2;
        
/* 正常提交表单 */
        window.form1.submit();
        }
// ----if(tb!=null)---->>
        return true;
    }
    
return false;    
}

 

------------5. action类中的代码

代码
//分解字符串
    public String[] SplitStr(String s) { 
        String[] ss 
= new String[200]; 
        
// 在每个逗号字符处进行分解。 
        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");
        
//是一个字符串   要分解 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;
    }

 

 

 ======方法2======(简单)===========

---------1. jsp页面中的代码

<table id="datashow" align="center" border="1" class="tb3" width="100%">
     <tr class="gridtitle"> 
      <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>
                         <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. action类中的代码

代码
//分解字符串
    public String[] SplitStr(String s) { 
        String[] ss 
= new String[200]; 
        
// 在每个逗号字符处进行分解。 
        ss = s.split(" "); 
        
return ss;
    } 

    
public String delete() throws Exception 
    {
        HttpServletRequest request 
= ServletActionContext.getRequest();
        String[] ids 
= request.getParameterValues("ids");
        System.out.println(
"ids[0]="+ids[0]);
        
if (ids == null)
        {
            
return SUCCESS;
        }

        
for (int i = 0; i < ids.length; i++) {
            System.out.println(
"print ids   " + ids[i]);
            LocationBean locationBean 
= new LocationBean();
            String[] ss
=SplitStr(ids[i]);
            locationBean.setLgort(ss[
0]);
            locationBean.setWerks(ss[
1]);
            locationService.deleteLocation(locationBean);
        }
        
return SUCCESS;
    }

 

---------3. 双主键情况下 *.hbm.xml中的写法-----

代码
<?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"
>
<hibernate-mapping>
    
<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>
</hibernate-mapping>

 

 

 

posted @ 2010-01-06 17:18  wj-conquer  阅读(1807)  评论(0编辑  收藏  举报