Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Franklin Phan
How to have portlet JSP retrieve attributes stored in ActionRequest?
July 24, 2009 3:23 AM
Answer

Franklin Phan

Rank: Regular Member

Posts: 137

Join Date: March 10, 2009

Recent Posts

I store a bean as an attribute of the ActionRequest in the @ProcessAction method (GenericPortlet) with the intent that the portlet JSP can access the bean via the ActionRequest attribute and display the bean's attributes:
1    @ProcessAction(name="testAction")
2    public void testActionURL(ActionRequest request, ActionResponse response)
3            throws PortletException, IOException {
4        ExpandedUser usr = new ExpandedUser();
5        usr.setFirstNamePreferred("John");
6        usr.setLastNamePreferred("Smith");
7        request.setAttribute("employee", usr);
8    }

JSP fragment:
 1<form id="<portlet:namespace/>test" action='<portlet:actionURL name="testAction"/>' method="post">
 2  <input type="hidden" name="var" value="whatever" />
 3  <input type="submit" value="Submit" />
 4</form>
 5
 6<logic:present name="emp">
 7  <bean:define id="emp" name="employee"/>
 8  <logic:notEmpty name="emp" property="firstNamePreferred">
 9    <logic:notEmpty name="emp" property="lastNamePreferred">
10      <bean:write name="emp" property="firstNamePreferred"/> <bean:write name="emp" property="lastNamePreferred"/>
11    </logic:notEmpty>
12  </logic:notEmpty>
13</logic:present>

But the bean does not exist any longer after the portlet is rendered.

How do I have portlet JSP retrieve attributes stored in ActionRequest?
Oliver Bayer
RE: How to have portlet JSP retrieve attributes stored in ActionRequest?
July 24, 2009 1:00 AM
Answer

Oliver Bayer

Rank: Liferay Master

Posts: 889

Join Date: February 18, 2009

Recent Posts

Hi,

as a workaround you can save your values/objects in the portletSession object.

within JSPPortlet:
1PortletSession portletSession = request.getPortletSession();
2portletSession.setAttribute("employee", usr);


in JSP:
1ExpandedUser employee = (ExpandedUser)portletSession.getAttribute("employee");


Note: you must include your expanded user object to get this to work and you should set a default value for employee so that you dont't get nullpointer exceptions from first start.
Franklin Phan
RE: How to have portlet JSP retrieve attributes stored in ActionRequest?
July 24, 2009 3:28 AM
Answer

Franklin Phan

Rank: Regular Member

Posts: 137

Join Date: March 10, 2009

Recent Posts

The problem was line 6 in the JSP fragment. It should have been:
1<logic:present name="employee">

I am wondering whether using an include (PortletRequestDispatcher) in the render method offers better advantage.