1

I'm having trouble understanding how ajax, a controller, and web-flow can interact.

As of right now, my project moves from page to page from different view states through the flow.

However, on some of these different pages, I have a few ajax calls that get directed to various controllers for server processing on a "currentObject". The services return an object, which I need to put back into the web-flow as my "currentObject".

Just to make things clear: I want to associate object A with object B, which object A is associated to the "currentObject". I do my server processing and complete the association(so "currentObject" is associated to object A which is associated to object B) and save the object to database. When I click on "create new object", web-flow still has the "currentObject" where object A is NOT associated with object B.

I want to put my updated "currentObject" into web-flow from my controller, so what is the best approach to modifying the object in web-flow through an ajax call?

Adam

Adam
  • 95
  • 1
  • 2
  • 8

1 Answers1

1

This is kind of a tricky one. I was in a similar situation and found this post to be helpful: Ajax + Spring Webflow

The basic problem is that the object in your webflow is serialized, so just doing an AJAX call and then modifying something in the DB as you would do with a normal controller won't work.

In my case, the basic model object is "plan" and I wanted to drop a child object called "task." I set up a transition in my webflow's XML config as follows:

<transition on="dropTask">
    <evaluate expression="planService.dropTaskFromPlan(requestParameters.taskID,  plan)" />
</transition>

The class "planService" will run through my "Plan" object, find the task with the given ID, and remove it.

Here's the ajax call:

var targetUrl = $("#actionPlanForm").attr("action") +     '&_eventId_dropTask=_eventId_dropTask';
$.ajax({
    type : 'POST',
    data: $("#actionPlanForm").serialize() + '&taskID=' + taskID,
    url : targetUrl
});
Community
  • 1
  • 1
user817851
  • 219
  • 1
  • 3
  • 10