单击行级别的刷新按钮时刷新行

时间:2013-12-02 10:55:04

标签: java jquery ajax jpa struts2

我有一个jsp,每行有一个表,我有刷新按钮,点击其中一行刷新两列,从ajax获取新数据,

问题:

单击刷新按钮刷新行,但是当我单击浏览器地址栏中的刷新图标时,之前的旧值将返回,这些值在数据库表中根本不存在。

这是我的jsp:

var file;
         function refreshRecord(value)
        {
            file = value;
        }

        $(document).ready(function(){
            $(".refresh").click(function(){
            var currentId=$(this).attr('id');
               var fileId=file;
               $.ajax({
               type:'post',
                url:'checkStatusAndNumRecs',
               data:{fileId:fileId},
                success:function(data)
               {
                    var obj=data.split(':');
                    var status=obj[0];
                    var numrecs=obj[1];
                    var statusId=currentId.replace("ref","status");
                    var recordsId=currentId.replace("ref","records");
                    alert("currentId"+currentId);
                    alert("after"+recordsId);
                    $('#'+statusId).html(status);
                    $('#'+recordsId).html(numrecs);
               },
               error:function(data)
            {
                $("#div1").html("It was a failure !!!");
            }
                });
                });
                });
        </script>    
        </head>
    <body>
    <%@include file="index1.html" %>
    <div class="box2">
     <div class="box3"> 
    <s:property value="userId"/>
    </div>  
        <center><h2>FILE STATUS</h2></center>
    <center> 

        <form action="Upload" method="post" enctype="multipart/form-data">
            <label for="myFile" class="text">Upload your file:</label>
            <input type="hidden" name="upload" value="upload"/>
            <input type="file" name="myFile" size="40"  class="file"/>
            <input type="submit" value="Upload" class="button"/>
            <input type="submit" value="Refresh" class="button"/>   
        </form>
        </center>        

          <center>
         <table border="1" class="displaytab" id="rtable">
         <s:if test="%{user.roles == 'admin'}">
         <tr>   <td  colspan="10" style="background:#7395B8;color:white;font-size:18px;font-weight:bold;"><center>Admin</center></td></tr>
         </s:if>
         <tr> 
         <th>FileId</th><th>File Name</th><th>Upload Date</th><th>#Records</th><th>Status</th><th>Estimated Time</th><th>Processed Records</th><th>Generate Report</th><th></th><s:if test="%{user.roles == 'admin'}"><th>Controls</th></s:if>
         </tr>

        <s:iterator value="uploadList" var="m" status="status">
            <tr>
            <td><s:property value="%{#m.fileId}" /></td>
            <td><s:property value="%{#m.fileName}" /></td>
            <td><s:property value="%{#m.uploadDate}" /></td>
            <td><div id="records<s:property value="%{#status.index}" />"><s:property value="%{#m.numRecords}" /></div></td>
            <td><div id="status<s:property value="%{#status.index}" />"><s:property value="%{#m.status}" /></div></td>
            <td>tbd</td>
            <td><s:property value="%{#m.numRecords}" /></td>
            <td><img src="images/generate.png" title="Generate Report"></td>
            <td id="button<s:property value="%{#status.index}" /> "><img src="images/refresh.png" title="Refresh" class="refresh" id="ref<s:property value="%{#status.index}" />" onclick="refreshRecord(<s:property value="%{#m.fileId}" />);"></td>
            <s:if test="%{user.roles == 'admin'}">
                 <td><a href=""><img src="images/details.png"></a>
                 <a href="#"><img src="images/plus.png" title="Add Instance"></a>
                 <a href="#"><img src="images/minus.png" title="Remove Instance"></a>
                 <a href="#"><img src="images/download.png" title="Download"></a>
                 <a href="#"><img src="images/reconnect.png" title="Reconnect"></a></td>

            </s:if>
            </tr>
         </s:iterator>
         </table>

这是我的actioon类执行方法:

public String execute()
{
    PersistenceService svc = PersistenceServiceImpl.getInstance();
    status = svc.getStatusByFileId(fileId);
    numRecords = svc.getNumRecordsByFileId(fileId);
    System.out.println("num records are "+numRecords);
    wholeString = status+":"+numRecords;
    return "SUCCESS";
}

struts.xml中:

<action name="Upload" class="com.mxui.UploadFileAction">        
      <result name="SUCCESS">fileupload.jsp</result>       
      <result name="LOGINERROR" type="redirect">ProcessLogin</result>
      <result name="PREVIEW" type="redirect">FilePreviewAction</result>       
      <result name="ERROR">error.jsp</result>
      </action>   

   <action name="FilePreviewAction" class="com.mxui.FilePreviewAction">
     <result name="SUCCESS">filepreview.jsp</result>
    <result name="JOBCREATED" type="redirect">Upload</result>
    <result name="ERROR" type="redirect">ProcessLogin</result>  
   </action>

请帮助我:

提前谢谢你。

0 个答案:

没有答案