views:

126

answers:

0

I'm trying to write a simple portlet using Spring 3 to run in Liferay. It's two pages - you can view an ordered list of items (they are just strings), and if you go to the edit page, you can change the order of the items in the list. On the edit page, you can either move an item up or down, one level at a time. So for example, when you click the up arrow next to an item, it swaps its position with the item above it, saves to the database, and returns to the same page, where the list should reflect the new order.

I have it working - mostly. The reordering saves to the database, but the list does not refresh. If I cancel the edit page and go back to the view only page, then the new order is reflected.

If I stay on the page and reorder it again by clicking an arrow next to a different item, then it does show the first change, just not the second.

In my jsp I am iterating through the listItems as such, and just displaying them in a bulleted list. This is the variable name, listItems:

<c:forEach var="listItem" items="${listItems}"

Next to each item I have an up and a down arrow (only showing one for brevity):

<a href="<portlet:actionURL><portlet:param name="myaction" value="reorderListAction" />
<portlet:param name="itemId" value="${listItem.id}" />
    <portlet:param name="direction" value="down" /></portlet:actionURL>">Down</a>

In my controller I use the following to populate listItems:

@ModelAttribute(value="listItems")
public List<ListItems> getListItems() {
  //This calls the dao and gets the ordered list from the database
  return listItemService.getListItems();
}

Clicking the arrow causes the list to get reordered by this method:

 @ActionMapping(params="myaction=reorderListAction")
 public void reorderListAction(ActionRequest request, ActionResponse response, SessionStatus sessionStatus)  {
  String listId = request.getParameter("itemId ");
  String direction = request.getParameter("direction");
  listItemService.reorderList(new Integer(listId), direction);
  response.setRenderParameter("myaction", "reorderList");
            //not sure if this is needed?
  sessionStatus.setComplete();

 }

And the RenderMapping to show the reorder page. This gets called both when coming from the view page, and also from the reorder method. I would expect that after the reorder method is called, it saves to the database, and it sets the render parameters so that this method gets called - at which point listItems should be updated with the new order and the edit page should refresh and have the list in the new order:

@RenderMapping(params="myaction=reorderList")
 public String reorderList() {
 //I added this in to try to force it to refresh the list - doesn't work
 getListItems();
 return "reorderList";
}

However, it doesn't work that way. Only by canceling the edit page and going back to the view page does the new order appear. I can see that it's saving the new order in the database, I'm just not sure why, when I try to refresh the page, it's not refreshing the list.

I'm new to Spring, and just going off a few examples I've seen. So I don't know if this is the best way to go about things or not.