I'm using Webflow 2.3.2 in an application, and on one step the user can add/delete from a list in the bound model object (they simply return to the current step after the modification). For example my object might look like this:
public class MyInfo implements Serializable {
List<String> myList = new ArrayList<String>();
}
Doing the "add" in webflow is no problem because I simply stick the new object on the end of the list, but for the "delete" I need to identify the element to delete. What I'm doing now is using the "currentEvent" predefined EL object and grabbing the raw event "value" which I've populated with the ID of the record to delete. I'm wondering if there's a more elegant way to do this, because this seems like going the long way around. Can anyone suggest a better way of doing this? Here's an illustration of what I'm doing now:
My JSP file (note the "delete" button):
<c:forEach items="${myInfo.myList}" var="listItem" varStatus="listItemStatus">
<c:set var="v" value="${listItemStatus.index}"/>
<div><form:input id="listItemValue_${v}" path="myInfo.myList[${v}]"/></div>
<div><button id="deleteItem_${v}" name="_eventId_deleteItem" type="submit" value="${v}">Delete This Item</button></div>
</c:forEach>
My "flow.xml" file:
<transition on="deleteItem" bind="false" validate="false">
<evaluate expression="flowService.deleteItem(flowScope.myInfo, currentEvent.attributes)" result="flowScope.myInfo" />
</transition>
My event handler:
public MyInfo deleteAccount(MyInfo myInfo, LocalAttributeMap currentEvent) {
myInfo.getMyList().remove(Integer.valueOf((String)(currentEvent.asMap().get("_eventId_deleteItem"))).intValue());
return myInfo;
}