Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Seeya S Kudtarker
Display data in JSP from action class
April 13, 2013 12:39 AM
Answer

Seeya S Kudtarker

Rank: Regular Member

Posts: 187

Join Date: January 15, 2013

Recent Posts

I am having a module wherein a user enters data in a jsp page and on submit of the form the data is given to the action class. Here is a snippet of the action class:

public void calculateLeaveDuration(ActionRequest areq, ActionResponse ares) throws Exception,PortletException,IOException {

String leavefromduration = areq.getParameter("leavefromduration");
String leavetoduration = areq.getParameter("leavetoduration");
String dleavefrom = areq.getParameter("dleavefrom");
}

here is my explanation of the module:
I have a jsp say applyforleave.jsp wherein the user applies for leave. On submit of the form the above class calculateLeaveDuration is called and email notification is sent for the approval of leave to the management. Here I also want to create a jsp (approve.jsp) where, the management also gets to see the leave details. And once the management approves the leave (i.e. submits the approve.jsp) I need to update the database.
My query is how do I pass the information from calculateLeaveDuration to approve.jsp ??

In general how should I pass the information from java class to jsp using actionrequest , actionresponse?
Meera Prince
RE: Display data in JSP from action class
April 13, 2013 2:09 AM
Answer

Meera Prince

Rank: Liferay Legend

Posts: 1110

Join Date: February 8, 2011

Recent Posts

HI

actionRequest.setAttribute(key,value);

In jsp page do like this.

renderRequest.getAttribute(key);
Seeya S Kudtarker
RE: Display data in JSP from action class
April 13, 2013 2:25 AM
Answer

Seeya S Kudtarker

Rank: Regular Member

Posts: 187

Join Date: January 15, 2013

Recent Posts

meera Prince,
Thanks for your reply.
Won't I need to specify the jsp page name in the java class?
Seeya S Kudtarker
RE: Display data in JSP from action class
April 13, 2013 2:47 AM
Answer

Seeya S Kudtarker

Rank: Regular Member

Posts: 187

Join Date: January 15, 2013

Recent Posts

meera,
I tried your suggestion but it isn't working.

How do I go about this problem?
Meera Prince
RE: Display data in JSP from action class
April 13, 2013 3:48 AM
Answer

Meera Prince

Rank: Liferay Legend

Posts: 1110

Join Date: February 8, 2011

Recent Posts

Hi send me you code snippet how did you set the attribute value in request object.
Seeya S Kudtarker
RE: Display data in JSP from action class
April 13, 2013 3:55 AM
Answer

Seeya S Kudtarker

Rank: Regular Member

Posts: 187

Join Date: January 15, 2013

Recent Posts

I have made a couple of changes after your suggestion.
I will paste the code in the next comment.
Seeya S Kudtarker
RE: Display data in JSP from action class
April 13, 2013 4:04 AM
Answer

Seeya S Kudtarker

Rank: Regular Member

Posts: 187

Join Date: January 15, 2013

Recent Posts

Here is the relevant code:

public void calculateLeaveDuration(ActionRequest areq, ActionResponse ares) throws Exception,PortletException,IOException {

String empName= areq.getParameter("empName");
String approvername= areq.getParameter("approvername");
String reason= areq.getParameter("reason");

areq.setAttribute(empName,empName);
areq.setAttribute(approvername,approvername);
areq.setAttribute(reason,reason);
}

and here is my jsp:
LeaveApproval.jsp

<portlet:defineObjects />
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Leave Approval</title>
</head>
<body>
<portlet:actionURL name="calculateLeaveDuration" var="calculateLeaveDurationURL" />

<aui:form name="calculateLeaveDuration" action="<%=calculateLeaveDurationURL.toString() %>" method="post" >
<%=renderRequest.getAttribute(empName); %>
<%=renderRequest.getAttribute(approvername); %>
<%=renderRequest.getAttribute(reason); %>
</aui:form>
</body>
</html>


please note that I have a jsp applyforleave.jsp which passes data to calculateLeaveDuration(). and from calculateLeaveDuration() I want to access the variables(after some modifications) in LeaveApproval.jsp
Rahul Pande
RE: Display data in JSP from action class
April 15, 2013 5:54 AM
Answer

Rahul Pande

Rank: Expert

Posts: 308

Join Date: July 6, 2010

Recent Posts

Hi Seeya,

PFA test portlet that might help you.

If you are using basic MVC portlet, then can send some object from action method to an jsp page using following code.


actionRequest.setAttribute({attribute name}, {attribute value});
actionResponse.setRenderParameter("jspPage", "{path of jsp page inside docroot folder}");



Thanks
Rahul
Attachments: test-portlet.rar (50.9k)
Manish Yadav
RE: Display data in JSP from action class
April 15, 2013 7:00 AM
Answer

Manish Yadav

Rank: Expert

Posts: 449

Join Date: May 26, 2012

Recent Posts

do below changes in your code and check whether its working



1<%=request.getAttribute(empName); %>
2<%=requestt.getAttribute(approvername); %>
3<%=request.getAttribute(reason); %>