最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to redirect to another JSP page via JavaScript in MVC portlet? - Stack Overflow

programmeradmin0浏览0评论

I am trying to open my form with filling out every text box on click of edit button on the HTML table where all my data is stored in list and each row has edit button. When I click on edit it will redirect to edit_restaurant.jsp page from restaurant.jsp page.

My restuarant.jsp page have one HTML table list in which it has edit button on each row and I want that on click of that edit button I will redirect to edit_restaurant.jsp page where all data can fill up with the id key which is bind to my edit button.

What I want is to get the id of button in another jsp button..am using liferay custom mvc portlet so can anyone guide me that how to make it possible.

Here is the snippet of code that I have tried.

Following is my column of edit button:

<td><input type="submit" id=<%=temprest.getPrimaryKey()s%> onclick="return getbuttonId('<%=temprest.getPrimaryKey() %>')" value="edit" /></td>      

...and on click of that button THE following Javascript will be invoked:

 <script type="text/javascript">
 function getbuttonId(sid){                 

        // document.editform.action=url;
        // document.editform.submit();
        var url="<%= editURL.toString()%>";
        window.location.href = url+"?sid="+sid;

        return false ;
  }

  </script>

My portlet action url is as follows:

<portlet:actionURL name="editRestaurant" var="editURL">

</portlet:actionURL>

...and the method I am calling via portlet action url is here in my action class:

public void editRestaurant(ActionRequest reqeust,ActionResponse response) throws Exception
{
  String str=  reqeust.getParameter("sid");
  long l=Long.valueOf(str);

  //Retriev table data using Primary key

  restaurant rest=restaurantLocalServiceUtil.getrestaurant(l);

  //Set Attribute which has all values of specified pk.
  reqeust.setAttribute("edit",rest );

  // Redirect to Jsp page which has Update form. 
  response.setRenderParameter("jspPage","/jsps/edit_restaurant.jsp");

}

I got error like this when I click on edit function

 java.lang.NoSuchMethodException: emenu.advertise.portlet.RestaurantPortlet.editRestaurant?sid=5(javax.portlet.ActionRequest, javax.portlet.ActionResponse)

Can somebody please guide me to fix this?

@

here i want that the sid value assigned to my button id should be transfer to this string value before page is redirects

<%      
 String restId=request.getParameter("sid");
//can i call sid value of javascript function getbuttonId() here
 %>
                             <portlet:actionURL name="editRestaurant" var="editURL">
      <portlet:param name="key" value="<%=restId %>"/>
       </portlet:actionURL>

I am trying to open my form with filling out every text box on click of edit button on the HTML table where all my data is stored in list and each row has edit button. When I click on edit it will redirect to edit_restaurant.jsp page from restaurant.jsp page.

My restuarant.jsp page have one HTML table list in which it has edit button on each row and I want that on click of that edit button I will redirect to edit_restaurant.jsp page where all data can fill up with the id key which is bind to my edit button.

What I want is to get the id of button in another jsp button..am using liferay custom mvc portlet so can anyone guide me that how to make it possible.

Here is the snippet of code that I have tried.

Following is my column of edit button:

<td><input type="submit" id=<%=temprest.getPrimaryKey()s%> onclick="return getbuttonId('<%=temprest.getPrimaryKey() %>')" value="edit" /></td>      

...and on click of that button THE following Javascript will be invoked:

 <script type="text/javascript">
 function getbuttonId(sid){                 

        // document.editform.action=url;
        // document.editform.submit();
        var url="<%= editURL.toString()%>";
        window.location.href = url+"?sid="+sid;

        return false ;
  }

  </script>

My portlet action url is as follows:

<portlet:actionURL name="editRestaurant" var="editURL">

</portlet:actionURL>

...and the method I am calling via portlet action url is here in my action class:

public void editRestaurant(ActionRequest reqeust,ActionResponse response) throws Exception
{
  String str=  reqeust.getParameter("sid");
  long l=Long.valueOf(str);

  //Retriev table data using Primary key

  restaurant rest=restaurantLocalServiceUtil.getrestaurant(l);

  //Set Attribute which has all values of specified pk.
  reqeust.setAttribute("edit",rest );

  // Redirect to Jsp page which has Update form. 
  response.setRenderParameter("jspPage","/jsps/edit_restaurant.jsp");

}

I got error like this when I click on edit function

 java.lang.NoSuchMethodException: emenu.advertise.portlet.RestaurantPortlet.editRestaurant?sid=5(javax.portlet.ActionRequest, javax.portlet.ActionResponse)

Can somebody please guide me to fix this?

@

here i want that the sid value assigned to my button id should be transfer to this string value before page is redirects

<%      
 String restId=request.getParameter("sid");
//can i call sid value of javascript function getbuttonId() here
 %>
                             <portlet:actionURL name="editRestaurant" var="editURL">
      <portlet:param name="key" value="<%=restId %>"/>
       </portlet:actionURL>
Share Improve this question edited Oct 22, 2012 at 7:25 BhavikKama asked Oct 22, 2012 at 6:56 BhavikKamaBhavikKama 8,79812 gold badges95 silver badges166 bronze badges 1
  • "following jquery will invoke" - I don't see any jQuery in your question; I assume you meant "JavaScript" and have edited your question to reflect that. – nnnnnn Commented Oct 22, 2012 at 7:09
Add a ment  | 

2 Answers 2

Reset to default 1

Please read this:

How to redirect to another webpage in JavaScript/jQuery?

Query is not necessary, and window.location.replace(...) will best simulate an HTTP redirect.

It is better than using window.location.href =, because replace() does not put the originating page in the session history, meaning the user won't get stuck in a never-ending back-button fiasco. If you want to simulate someone clicking on a link, use location.href. If you want to simulate an HTTP redirect, use location.replace.

For example:

// similar behavior as an HTTP redirect
window.location.replace("http://stackoverflow.");

// similar behavior as clicking on a link
window.location.href = "http://stackoverflow.";

Anyways had solved my problem with the following code:

function getbuttonId(sid){

alert("Are You Sure You want to Edit");
// document.editform.action=url;
// document.editform.submit();
var textbox = document.getElementById('hiddenkey'); 

textbox.value=sid; 

document.editform.action = "<%=editURL.toString() %>";
document.editform.submit();

return false ;

}

and onclick of button I am calling the above javascript method. So it works good.

Actually what I want was the id of particular button which is clicked so I am storing that id in hidden key and after form submit action in java script I am redirecting to page I want and then I can get the value of hidden key field from the request.getattribute(hiddenkey field name).

发布评论

评论列表(0)

  1. 暂无评论