ColdBox3.8.0/CF10 - ColdBox Logic Flow


After trying several ways, I think I’m at a lost of how to adapt the following to coldbox framework.

When a search results is displayed, I’d like to display the filters list on the left side with a count for each filter item. Was able to do this in the old way, but breaking it apart and adapting to coldbox framework is challenging. The only way I could think of doing this with ColdBox is to pass in value for ALL possbile filters to get results…and then in the view be able to display the count. But logically, that doesn’t make sense to me b/c coming from desktop application development, I understand that a query is performed upon the selection of an item…

Am I approaching this solution incorrectly in ColdBox?

Thanks for your help.

Are you templating out the filters in a ColdBox view, or building them via JavaScript on the client?



ColdBox Platform Evangelist
Ortus Solutions, Corp

ColdBox Platform:

I am templating the filters in a ColdBox View (searchFilters.cfm). Is this not an ideal way?


No, there’s nothing wrong with that, I’m just trying to understand what you’re doing. Can you elaborate more on what specifically is giving you issues? Generally speaking, your views can do everything they used to without a framework-- they’re just controlled (and get data from) your handlers.



ColdBox Platform Evangelist
Ortus Solutions, Corp

ColdBox Platform:

I have the following:

searchFormView - accepts the search value entered
searchController - event1 (gets data using search valued entered); event2(gets data based on filter item selected)
(I broke the following to 3 files to keep length of file down)
searchFiltersView - displays all possible filters (along with counts)
resultsView - displays the results table if there are any results
searchResultsView - displays resultsView and searchFiltersView as applicable.

So the issue is:
I cannot display the filter count in the searchFiltersView unless the query has already been performed in event2() for the selected filter.

I got it to work where as a filter item is selected, the event2() is called… that works, but on the view the users cannot see the count.

So, I attempted to setNextEvent(event2, filterItem) at the beginning of the searchResultsView… but got in an infinite loop it seems… Is calling a nextEvent even possible?

Comments inline below.

Thank you Andrew for taking the time to explain things for me…yes, I am new to ColdBox…and ColdFusion, so learning as I go here! :slight_smile:

If I understand correctly, basically, at the entry point (index) of the Handler, all filters (X, Y, Z, …) query should be performed and stored them in the rc/prc? And as the user selects a filter item on the view, then just use an existing rc/prc values to refresh the view without calling an event in the Handler, b/c calling SetNextEvent would clear out the previous event rc/prc values. Am I correct?

My files are kind of long, I’d hate to take up so much of your time reading my code…if I cut them down, then it won’t make sense of what I’m trying to do…

Thank you for your patience.

Yes that is the basics of it.

With forms from views, if you take a step back and see it as coming from the client. You will be calling an event and passing all this into the controller anyway.

If you do something like this.

void function search(event, rc, prc) {
writeDump(prc); abort;

You will notice that the form fields and any url variables are now store into the RC or the public Request Context, this means that in your controller you can access them via the rc scope anyway. But there are times like form fields such as radio buttons that aren’t passed unless they are actually true.

As with ColdFusion you need to param these so they exist, which sets it to a default value so that anything that request it, wont fail with an undefined error. You could always just place isDefined or structExists, etc. but at the end of the process it is easier to scope it is existence once.

With long files, I can’t stress how important it is to break things down into smaller manageable code. When doing OOP against procedural, it is a big learning curve and mindset to always be thinking now what if what I am writing can be refactored to a general location. Which is why services and models exist in the first place to segregate that logic.

Controllers are no different here, most business logic, if not all should be in models and services at layers that they belong too. By then splitting this all into a view, we remove all the business logic and other code that has no impact on displaying information back to the client application.

Which is the basic principles of an MVC, once you apply that logic to ColdBox you can then see how to begin moving sections of code to their rightful places. Be patient, read the ColdBox documentation not once, not twice but a lot more than you might normally. The reason is that when you begin understanding one aspect of ColdBox other areas start to make more sense if you re-read other sections again.

Hope that helps.

Sorry forgot to answer the question about events.

Here is how to look at it, the event is something that returns data to a caller. In the case of viewlets, when we call an event from in the view the event is actually run in the context of the already running event and in basic terms then this is like using the request scope in ColdFusion and everything will live for the entire request or untill you kill / delete the variable yourself.


Thank you for your awesome guidance. Yes, you’re right, the hardest part for me is deciding which part of code in a procedural file belong where in the MVC world.

I will redo the logic flow with your suggestions in mind. Thank you!