I'm trying to write a little piece of code to show in a portlet for Liferay the name of the user logged.
My problem, a part of a programming problem, is that I don't understand how exactly is the connection between a java class and the view.jsp file.
I know and I'm able to show the user name and photo just with the view.jsp file, but I'm not able to achieve using also a java class.
I've tried it with the processAction() method and the doView() method. I guess that we need to save the parameters to show the information in the actionResponse to render it in the portlet, but I'm in fact a little bit lost and messy. One of my question, for example is: Should I write also in the view.jsp file? Or can I do everything only with my java class? I attach the code of my java class.
Any help will be very greatful. Many thanks in advance. Rafa
public class UserInfo extends MVCPortlet{
@Override
public void processAction( ActionRequest actionRequest, ActionResponse actionResponse)
throws IOException, PortletException
{
ThemeDisplay themeDisplay = (ThemeDisplay)
actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
User user = themeDisplay.getUser();
PortletPreferences prefs = actionRequest.getPreferences();
String userName = (String) actionRequest.getParameter("UserInfo");
userName = user.getFullName();
if (userName != null)
{
prefs.setValue("UserInfo", userName);
prefs.store();
}
actionResponse.setRenderParameter("userName", userName);
super.processAction(actionRequest, actionResponse);
}
}