Foros de discusión
Send object from action method to jsp
Hari Dhanakoti, modificado hace 11 años.
Send object from action method to jsp
New Member Mensajes: 14 Fecha de incorporación: 22/07/12 Mensajes recientes
Am a new bie with liferay and facing some issues with passing values back and forth.
I have a method "public void getNextComments(ActionRequest actionRequest, ActionResponse actionResponse)". I want to send an ArrayList from the MVCPortlet (liferay) to jsp. How can i retrieve it from the jsp end?
I tried setting up object as attribute but not sure how to retrieve the same on the UI.
actionRequest.setAttribute("socialactivities", socialActivities);
(HTTPServletRequest) request.setAttribute("socialactivities", socialActivities);
Please help me on this.
I have a method "public void getNextComments(ActionRequest actionRequest, ActionResponse actionResponse)". I want to send an ArrayList from the MVCPortlet (liferay) to jsp. How can i retrieve it from the jsp end?
I tried setting up object as attribute but not sure how to retrieve the same on the UI.
actionRequest.setAttribute("socialactivities", socialActivities);
(HTTPServletRequest) request.setAttribute("socialactivities", socialActivities);
Please help me on this.
Pinkesh Gandhi, modificado hace 11 años.
RE: Send object from action method to jsp
Junior Member Mensajes: 99 Fecha de incorporación: 27/01/12 Mensajes recientes
Hi Hari,
Yes, you can set the list object into actionRequest and then can retrieve it on jsp in following way,
In your MVCPortlet,
And at jsp side,
I hope it may resolves your problem.
Yes, you can set the list object into actionRequest and then can retrieve it on jsp in following way,
In your MVCPortlet,
actionRequest.setAttribute("socialactivities",socialActivities);
And at jsp side,
<%
List socialActivities = (List) renderRequest.getAttribute("socialactivities");
%>
I hope it may resolves your problem.
Hari Dhanakoti, modificado hace 11 años.
RE: Send object from action method to jsp
New Member Mensajes: 14 Fecha de incorporación: 22/07/12 Mensajes recientes
I tried the same but couldn't get object on the jsp side. Do i miss any other configuration?
Java code:
List<SocialActivity> socialActivities = SocialActivityLocalServiceUtil.getUserActivities(user2Id, end, activitiesPerPage+end);
actionRequest.setAttribute("socialactivities", socialActivities);
JSP code:
List fetchedActivities = (List) renderRequest.getAttribute("socialactivities");
List fetchedActivities = (List) request.getAttribute("socialactivities");
Both of these didn't work any other clues to resolve the same?
Java code:
List<SocialActivity> socialActivities = SocialActivityLocalServiceUtil.getUserActivities(user2Id, end, activitiesPerPage+end);
actionRequest.setAttribute("socialactivities", socialActivities);
JSP code:
List fetchedActivities = (List) renderRequest.getAttribute("socialactivities");
List fetchedActivities = (List) request.getAttribute("socialactivities");
Both of these didn't work any other clues to resolve the same?
Jignesh Vachhani, modificado hace 11 años.
RE: Send object from action method to jsp
Liferay Master Mensajes: 803 Fecha de incorporación: 10/03/08 Mensajes recientes
Please try this :
in process action :
actionRequest.setAttribute("socialactivities", socialActivities);
in render method :
String socActivit y= renderRequest.getAttribute("socialactivities");
renderRequest.setAttribute("socialactivities", socActivit );
In JSP:
List fetchedActivities = (List) request.getAttribute("socialactivities");
in process action :
actionRequest.setAttribute("socialactivities", socialActivities);
in render method :
String socActivit y= renderRequest.getAttribute("socialactivities");
renderRequest.setAttribute("socialactivities", socActivit );
In JSP:
List fetchedActivities = (List) request.getAttribute("socialactivities");
Rewati Raman, modificado hace 11 años.
RE: Send object from action method to jsp
Junior Member Mensajes: 97 Fecha de incorporación: 24/02/12 Mensajes recientesHari Dhanakoti:
Am a new bie with liferay and facing some issues with passing values back and forth.
I have a method "public void getNextComments(ActionRequest actionRequest, ActionResponse actionResponse)". I want to send an ArrayList from the MVCPortlet (liferay) to jsp. How can i retrieve it from the jsp end?
I tried setting up object as attribute but not sure how to retrieve the same on the UI.
actionRequest.setAttribute("socialactivities", socialActivities);
(HTTPServletRequest) request.setAttribute("socialactivities", socialActivities);
Please help me on this.
you just need to do two things
first:
with your actionRequest setAttrribute wat object you want to send with attribute name in double quote
second:
with your actionResponse redirect where you want to use that object
code would be like this
at MVCPortlet
actionRequest.setAttribute("Object",ArrayListObject);
actionResponse.setRenderParameter("jspPage","/html/reference.jsp");
at the respective Jsp you need to fetch the object
List myArrayList=new ArrayList();
myArrayList=(List)request.getAttribute("Object");
now you can use your ArrayList
Thanks
Rewati Raman
Hari Dhanakoti, modificado hace 11 años.
RE: Send object from action method to jsp
New Member Mensajes: 14 Fecha de incorporación: 22/07/12 Mensajes recientes
I tried setting up the parameters in actionReponse and got he following Exception
actionResponse.setRenderParameter("jspPage","/super_wall/view_wall.jspf");
and
actionResponse.setRenderParameter("socialactivities", socialActivities);
08:50:56,629 ERROR [jsp:996] java.lang.IllegalStateException: Set render parameter has already been called
actionResponse.setRenderParameter("jspPage","/super_wall/view_wall.jspf");
and
actionResponse.setRenderParameter("socialactivities", socialActivities);
08:50:56,629 ERROR [jsp:996] java.lang.IllegalStateException: Set render parameter has already been called
Jitendra Rajput, modificado hace 11 años.
RE: Send object from action method to jsp
Liferay Master Mensajes: 875 Fecha de incorporación: 7/01/11 Mensajes recientes
Are you using sendRedirect() at the end of your processAction ?
Hari Dhanakoti, modificado hace 11 años.
RE: Send object from action method to jsp
New Member Mensajes: 14 Fecha de incorporación: 22/07/12 Mensajes recientes
Method definition starts as such
@ProcessAction(name = "getNextComments")
public void getNextComments(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {
actionRequest.setAttribute("socialactivities", socialActivities); / Not working
actionResponse.setParameter("jspPage,"/asdf/asdf..jsp"); / Throws Exception
}
@ProcessAction(name = "getNextComments")
public void getNextComments(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {
actionRequest.setAttribute("socialactivities", socialActivities); / Not working
actionResponse.setParameter("jspPage,"/asdf/asdf..jsp"); / Throws Exception
}
Harish Kumar, modificado hace 11 años.
RE: Send object from action method to jsp
Expert Mensajes: 483 Fecha de incorporación: 31/07/10 Mensajes recientes
Hi Hari,
1. Set the list in the actionRequest as
actionRequest.setAttribute("socialactivities", socialActivities);
2. In jsp use the request (not renderRequest) object to get the attribute as
List<String> list = (List<String>)request.getAttribute("socialactivities");
Here I assume that list is of type String. modify according to your list type.
Instead of setting the jsp page in action method as you are doing -
actionResponse.setParameter("jspPage,"/asdf/asdf..jsp"); / Throws Exception
Set a renderParameter in action method and fetch that value in render method. based on this value redirect the user to desired page.
Regards,
Hari Dhanakoti:
Method definition starts as such
@ProcessAction(name = "getNextComments")
public void getNextComments(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {
actionRequest.setAttribute("socialactivities", socialActivities); / Not working
actionResponse.setParameter("jspPage,"/asdf/asdf..jsp"); / Throws Exception
}
1. Set the list in the actionRequest as
actionRequest.setAttribute("socialactivities", socialActivities);
2. In jsp use the request (not renderRequest) object to get the attribute as
List<String> list = (List<String>)request.getAttribute("socialactivities");
Here I assume that list is of type String. modify according to your list type.
Instead of setting the jsp page in action method as you are doing -
actionResponse.setParameter("jspPage,"/asdf/asdf..jsp"); / Throws Exception
Set a renderParameter in action method and fetch that value in render method. based on this value redirect the user to desired page.
Regards,
Rewati Raman, modificado hace 11 años.
RE: Send object from action method to jsp
Junior Member Mensajes: 97 Fecha de incorporación: 24/02/12 Mensajes recientesHari Dhanakoti:
I tried setting up the parameters in actionReponse and got he following Exception
actionResponse.setRenderParameter("jspPage","/super_wall/view_wall.jspf");
and
actionResponse.setRenderParameter("socialactivities", socialActivities);
08:50:56,629 ERROR [jsp:996] java.lang.IllegalStateException: Set render parameter has already been called
you cannot use twice setRenderParameter
setRenderParameter is used for page redirection
so before setting setRenderParameter you need to use
actionRequest.setAttribute("ArrayListName",ArrayList);
but you were using setRenderParameter with actionResponse for setting attribute that is why you are getting that exception
use the above code instead your problem will get resolved
Regards,
Rewati Raman
Natasha Pelovska, modificado hace 11 años.
RE: Send object from action method to jsp
New Member Mensaje: 1 Fecha de incorporación: 5/12/12 Mensajes recientes
Hello, I am having the same problem and i tried everything from above but it doesn't work.
The method in my portlet i have:
request.setAttribute("subject",subject);
response.setRenderParameter("jspPage","/html/display/second.jsp");
where subject is a database object
then in second.jsp i am trying to get subject
Subject subject = (Subject)renderRequest.getAttribute("subject");
i tried like this also
Subject subject=new Subject();
subject=(Subject)request.getAttribute("subject");
but it always gives me null pointer exception
btw in my first jsp i already have set action of the form to corresponding url.
The method in my portlet i have:
request.setAttribute("subject",subject);
response.setRenderParameter("jspPage","/html/display/second.jsp");
where subject is a database object
then in second.jsp i am trying to get subject
Subject subject = (Subject)renderRequest.getAttribute("subject");
i tried like this also
Subject subject=new Subject();
subject=(Subject)request.getAttribute("subject");
but it always gives me null pointer exception
btw in my first jsp i already have set action of the form to corresponding url.