I have a couple of days of frustration into this so I am asking for help. I have a portlet and the view.jsp has an option for the user to add a new record (which works fine) or to search the DB for existing records. The user selects from a dropdown and presses Search. This is picked up by processAction which sends it to the doGetLessonsList method. After grabbing the search parameter from the form, a db method is called that completes the search, creates and returns an arraylist of object, Lesson. Now I want to send that arraylist back to the
jsp for display. So I planned to use the setRenderParameter for this. I had to convert the arraylist of Lesson objects to a
String array and that's where it shuts down. I have tried 3 different methods of converting my arraylist and nothing has worked. The 3 different tries are commented out in the code below. It appears to be ArrayStoreException error.
The arraylist isempty
test comes back False and the number of records comes back as 2 so I know the arraylist (lArray) is populated.
Here's my code - if anyone can provide some input, I would appreciate the advice or corrections.
private void doGetLessonsList (ActionRequest request, ActionResponse response)
throws PortletException, IOException
{
// get the search parameter from the form
String sSearchString = request.getParameter("searchRO");
try
{
ArrayList lArray = new ArrayList();
// call the method to perform the search and return as Arraylist
lArray = dbInterface.getLessonsList(sSearchString);
//lets test to see if anything is there
boolean arraytest = lArray.isEmpty();
String s = String.valueOf(arraytest);
int x = lArray.size();
String t = Integer.toString(x);
// convert arraylist to array as required by set.renderParameter
//neither of these 3 methods work!!
//String sArray [] = new String [x];
//lArray.toArray (sArray);
//String[] sArray = (String[])lArray.toArray(new String[lArray.size()]);
//String[] sArray = (String[]) lArray.toArray(new String[0]);
// get the size of the array so we can pass this also
// but convert to string first
//int arraysize = java.util.Arrays.asList(sArray).size();
//String val = String.valueOf(arraysize);
// make 3 items available to view.jsp
response.setRenderParameter("ArrayEmpty", s);
response.setRenderParameter("ArraySize", t);
//response.setRenderParameter("ArrayResults", sArray);
}
catch (Exception e)
{
e.printStackTrace();
}
}