留言板
Send object from action method to jsp
Hari Dhanakoti,修改在11 年前。
Send object from action method to jsp
New Member 帖子: 14 加入日期: 12-7-22 最近的帖子
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,修改在11 年前。
RE: Send object from action method to jsp
Junior Member 帖子: 99 加入日期: 12-1-27 最近的帖子
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,修改在11 年前。
RE: Send object from action method to jsp
New Member 帖子: 14 加入日期: 12-7-22 最近的帖子
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,修改在11 年前。
RE: Send object from action method to jsp
Liferay Master 帖子: 803 加入日期: 08-3-10 最近的帖子
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,修改在11 年前。
RE: Send object from action method to jsp
Junior Member 帖子: 97 加入日期: 12-2-24 最近的帖子Hari 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,修改在11 年前。
RE: Send object from action method to jsp
New Member 帖子: 14 加入日期: 12-7-22 最近的帖子
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,修改在11 年前。
RE: Send object from action method to jsp
Liferay Master 帖子: 875 加入日期: 11-1-7 最近的帖子
Are you using sendRedirect() at the end of your processAction ?
Hari Dhanakoti,修改在11 年前。
RE: Send object from action method to jsp
New Member 帖子: 14 加入日期: 12-7-22 最近的帖子
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
}
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,修改在11 年前。
RE: Send object from action method to jsp
Junior Member 帖子: 97 加入日期: 12-2-24 最近的帖子Hari 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,修改在11 年前。
RE: Send object from action method to jsp
New Member 发布: 1 加入日期: 12-12-5 最近的帖子
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.