Forums de discussion
Send object from action method to jsp
Hari Dhanakoti, modifié il y a 11 années.
Send object from action method to jsp
New Member Publications: 14 Date d'inscription: 22/07/12 Publications récentes
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, modifié il y a 11 années.
RE: Send object from action method to jsp
Junior Member Publications: 99 Date d'inscription: 27/01/12 Publications récentes
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, modifié il y a 11 années.
RE: Send object from action method to jsp
New Member Publications: 14 Date d'inscription: 22/07/12 Publications récentes
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, modifié il y a 11 années.
RE: Send object from action method to jsp
Liferay Master Publications: 803 Date d'inscription: 10/03/08 Publications récentes
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, modifié il y a 11 années.
RE: Send object from action method to jsp
Junior Member Publications: 97 Date d'inscription: 24/02/12 Publications récentesHari 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, modifié il y a 11 années.
RE: Send object from action method to jsp
New Member Publications: 14 Date d'inscription: 22/07/12 Publications récentes
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, modifié il y a 11 années.
RE: Send object from action method to jsp
Liferay Master Publications: 875 Date d'inscription: 07/01/11 Publications récentes
Are you using sendRedirect() at the end of your processAction ?
Hari Dhanakoti, modifié il y a 11 années.
RE: Send object from action method to jsp
New Member Publications: 14 Date d'inscription: 22/07/12 Publications récentes
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, modifié il y a 11 années.
RE: Send object from action method to jsp
Expert Publications: 483 Date d'inscription: 31/07/10 Publications récentes
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, modifié il y a 11 années.
RE: Send object from action method to jsp
Junior Member Publications: 97 Date d'inscription: 24/02/12 Publications récentesHari 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, modifié il y a 11 années.
RE: Send object from action method to jsp
New Member Envoyer: 1 Date d'inscription: 05/12/12 Publications récentes
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.