I use Ajax (Jquery) quite often to send forms off for processing in ColdFusion. I send the form to a CFC which returns results and errors back to the user through Ajax notificatitons.
The forms can be quite large (think full HTML pages with additional inputs) and require a lot of logic in the CFC to process correctly depending on what options were selected in the form.
Because each function within the CFC can be large (maybe 1200 lines of code), I am getting the dreaded "branch target offset too large for short" error from ColdFusion. To get around this I have put some code into a .cfm file and used <cfinclude>
to get the code back into the cfc which 'solves' the problem but I feel is confusing when trying to organise all the little snippets to associate with a particular CFC. It also may be an inefficient way of working.
I would like to know how other ColdFusion users structure/handle processing forms using CFCs which do a lot of additional stuff while getting the form data into a database.
Some options I have thought of are:
- Make 'shell' functions for Create, Update, Read, and Delete actions which don't have much code in them
- Within the shell functions
cfinclude
all the code snippets by sub-function from many other .cfm files to keep the code to a minimum - OR invoke other CFCs which do the sub-functions and pass in the form variables as arguments to them
The options above will end up with me having a structure like this (which I don't like):
Article.cfc (CreateArticle, EditArticle etc)
CreateArticle_InsertImage.cfc
CreateArticle_ProcessBodytext.cfc
CreateArticle_InsertUser.cfc
CreateArticle_CheckIfExistingArticle.cfc
EditArticle_UpdateImage.cfc
EditArticle_UpdateBodytext.cfc
EditArticle_CheckIfExistingArticle.cfc
I would end up creating a new CFCs for each function rather than them being classes/objects in their own right. They could be CFM files instead (and use <cfinclude>
but it seems wierd to do this like this. Is there a alternative/better/standard way anyone knows of?