I have a portlet on Liferay portal where I invoke action from a .jsp page. I would like to pass a String array to another .jsp page where this array will be displayed. However, no values are being passed at all.
I am able to pass some String values using String something = (String)prefs.getValue("something", "something"); but this doesnt work for arrays.
This is my view.jsp from which I invoke the actionRequest (I will only show parts of the code, it would be too long otherwise):
<portlet:actionURL var="loadMessages" name="loadMessages">
<portlet:param name="jspPage" value="/view.jsp" />
</portlet:actionURL>
This is the loadMessages() function in my Java class:
public void loadMessages(ActionRequest actionRequest, ActionResponse actionResponse)
throws IOException, PortletException {
manager.loadFromDB();
ArrayList<Message> messagesObject = manager.getMessages();
// we must save our messages as strings
String[] messages = new String[messagesObject.size()];
for (int i=0; i<messagesObject.size(); i++) {
String msg = "";
Message message = messagesObject.get(i);
msg += message.getMsgid() + "\n";
msg += message.getSender() + "\n";
msg += message.getReceiver() + "\n";
messages[i] = msg;
}
// save
if (messages != null) {
actionRequest.setAttribute("messages", messages);
System.out.println(messages.length + " messages loaded!");
}
}
This works fine so far: I am getting "x messages loaded!" messages.
The problem comes when I want to access this array in my display.jsp file:
<%
String[] messages = (String[])renderRequest.getAttribute("messages");
if (messages == null) {
System.out.println("NULL MESSAGES");
} else {
System.out.println(messages[0]);
}
%>
I am getting, that my array is NULL here? What changes do I have to take to access the array I saved in my actionRequest phase?
Second question: Is it possible to pass Java object to .jsp page? I am guessing that this works only for Strings but it would be definitely cool to work with objects!
Thanks for any answer!