刷新portlet的<div>标记中的内容</div>

时间:2012-07-02 04:23:25

标签: javascript jquery html liferay portlet

我的Liferay有问题。我正在做以下事情:

function deleting() {
    <portlet:actionURL var="deletePolyURL"> 
        <portlet:param name="jspPage" value="/deletePoly.jsp" /> 
    </portlet:actionURL>  

    <portlet:renderURL var="listingURL"> 
        <portlet:param name="jspPage" value="/listing.jsp" /> 
    </portlet:renderURL>

    $.post(
        "<%=deletePolyURL%>",
        {
            ids:ch.toString()
        },
        function(per) {
              $("#WRAPlist").load("<%=listingURL%>");
               }
    );
}

<div>已重新加载,但在此<div>中,整个Liferay页面已加载而不仅仅是我的页面,请参见图像的右侧。

enter image description here

我做错了什么?

deletePoly.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>


<%
            {
              //String st = request.getParameter("ids");
              String st = ParamUtil.getString(request,"ids");
              out.println("NE TORT");
                        String[] id_str;
                        id_str=st.split(",");
              Class.forName("org.postgresql.Driver");
                Connection connect= null;
                connect = DriverManager.getConnection("jdbc:postgresql://localhost:5432/postgis","postgres","123456");
                Statement state = null;
                state = connect.createStatement();
                int id;
                String sql1="";
                String sql2="";
                for(int i=0;i<id_str.length;i++)
                {
                    id=Integer.parseInt(id_str[i]);
                    sql1="DELETE FROM filestatus WHERE id=?";
                    PreparedStatement stmt1 = connect.prepareStatement(sql1);
                    stmt1.setInt(1, id);
                    stmt1.execute();
                    sql2="DELETE FROM filedata WHERE id=?";
                    PreparedStatement stmt2 = connect.prepareStatement(sql2);
                    stmt2.setInt(1, id);
                    stmt2.execute();
                }
                state.close();
                connect.close();
                Integer per=1;
                out.println(per);
              }

         %>

listing.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
Class.forName("org.postgresql.Driver");
Connection conn= null;
conn = DriverManager.getConnection("jdbc:postgresql://localhost:5432/postgis","postgres","123456");
Statement sta = null;
sta = conn.createStatement();
String fileName= "";
Integer fileId=null;
String fileStatus ="";

ResultSet r=sta.executeQuery("SELECT id, name, status FROM filestatus");
String acc="Принят                   ";
while(r.next())
{
    fileId=r.getInt("id");
    fileName=r.getString("name");
    fileStatus=r.getString("status");   
    if(fileStatus.equalsIgnoreCase(acc))
    {
        out.write("<input type='checkbox' class='myclass' id='check"+fileId+"' name='"+fileName+"' value='"+fileId+"'/><label for=check"+fileId+">"+fileName+"</label><br>");   
  }
    else
    {
        out.write("<input type='checkbox' class='myclass' id='check"+fileId+"' name='"+fileName+"' value='"+fileId+"'/><label for=check"+fileId+" style='color:blue'>"+fileName+"</label><br>");

    }
}
r.close();
sta.close();
conn.close();

%>
</body>
</html>

我刷新问题。

2 个答案:

答案 0 :(得分:0)

我建议您需要<portlet:resourceURL>而不是renderURL来加载jsp,因为它是一个ajax请求,您需要在portlet类中使用serveResource方法加载listing.jsp

<portlet:resourceURL var="listingURL"> 
    <portlet:param name="jspPage" value="/listing.jsp" /> 
</portlet:resourceURL>

希望这有帮助。

答案 1 :(得分:0)

如果您不想通过资源处理来自行处理整个Ajax调用,您还可以将回复限制为仅包含portlet,而不是整个页面:

<%@ page import="com.liferay.portal.kernel.portlet.LiferayWindowState" %>

<portlet:actionURL var="deletePolyURL" windowState="<%=LiferayWindowState.EXCLUSIVE.toString() %>"> 
    <portlet:param name="jspPage" value="/deletePoly.jsp" /> 
</portlet:actionURL>

看看这是否有帮助 - 否则你应该像Prakash建议的那样使用<portlet:resourceURL>(并在你的portlet的资源服务方法中处理这个过程。