CFML-MachII and AJAX architecture
This being my first post, I will not start out light. I have spent 6 months getting my feet wet with Mach-II and am facing a conundrum…, of course, meanwhile my boss (our local expert) is on vacation! So, here goes…
Requirement: Have one package (domain) call another, where both domains are formatting JSON. I have worked with MII for 6 months and am now building a form generator. To work with the validation library (idealforms) I have chosen, I have a Question library which formats the JSON at the View layer. Now for a different requirement, I need the whole form to be passed back as one big JSON to the browser. What layer of Form library should talk to what layer of the Question library. For example, should I move the Question JSON-formatting to the Question library’s Listener level and have the Form library talk to it from the controller level?
Here’s what the experts have said:
- Co-worker: Have session layer talk to service layer. So, in essence, the Question session (formQuestionService.cfc) format the individual question JSON objects.
- Online Forum: “I think communicating on the controller level would work. The other option would be to create a remote service CFC and have it expose remote methods that you can call via JS accepting and return JSON. Finally you could take a look at the new endpoints feature in Mach II 1.9 which was setup to provide nice infrastucture for REST based services which is basically what you are building.” … “If you are going to use the listener I would format the json as part of the listener code or as part of the view code. I try to make sure my service layer doesn’t know about json or html unless I make a special remote service whose job it is to just deal with json from the browser.“
I was going with the co-worker’s plan because she can forecast the Boss’ more subtle requirements better than anyone, but the bolded part about the listner level makes even more sense. Happy Mach-ing!