Omar Wagih
Omar Wagih

Reputation: 8742

Play framework 2.0 data binding flow

I have a pipeline which I would like to work like this

Section A

  1. User navigates to form A. Selects some pictures for upload
  2. Form is submitted, images are uploaded, processed with Java in the backend and returned to user in summary page A
  3. User selects which photos to further process then clicks "Further process selected"

Section B

  1. Selected photos from A.3 are processed and displayed along with form B
  2. User selects some more options and submits
  3. Photos are displayed in form B's summary page (summary page B)

I have section A implemented. The paths to the images are stored in form A's model. In summary A, when the user checks a photo, a javascript array variable is updated with the selected images' paths What I am having trouble with passing this javascript variable to form B

Is this possible? is there an alternative? Please let me know if I haven't explained my self well

Thanks

Upvotes: 1

Views: 350

Answers (1)

Richard Close
Richard Close

Reputation: 1905

Supplying the javascript variable to Form B is straightforward -- you just add it as a global Javascript variable in the generated page. So your template would have:

<script type="text/javascript">
var theArrayData = @Html(theJavaScriptVariable.toString)
</script>

You could either recompute theJavaScriptVariable in your controller before passing it to the template, or you may be able to submit it along with the rest of Form A as a hidden field, and cache it with the user's session. You would need to serialise it (e.g. with the jquery JSON library), and probably deal with escaping.

Upvotes: 2

Related Questions