Learning Coldbox: Validating

I have tried many ways to validate data in ColdBox, and there are many ways! I have used 3rd party plug-ins and followed many blogs posts on the subject. I want to share one of my preferred ways to validate data in ColdBox. Its not the most polished method and it has its flaws (persisting values) but it has worked well for me!

First I will create an example handler (show below). This handler is used to display School data based on the ID and School URL passed to it. I won't go into the Application or the model here.

[More]

IE and XML issue over SSL

I spent most of Friday morning with a strange ColdFusion and XML issue. A number of customers reported that a flash application we run was hanging on the loading screen. The flash accepts a XML file created by ColdFusion. The flash application appeared to be working in FireFox and Chrome but not in good old IE! The plot thickens, when the request was made on port 80 and not SSL the flash worked in IE and the load was successful.

The problem got even more strange, some IE users were successfully loading the flash. The only difference between the two IE users where some had installed a set of IE updates (xml did not load) and the other had not (xml worked, flash loaded).

[More]

Google and Breadcrumbs

Something the CF devs out there maybe interested in. Google has been experimenting with an improvement that replaces the standard website URL's in 'some' search results with a hierarchy showing the precise location of the page on the website.

Read more at my other blog post here Google Breadcrumbs

Learning ColdBox: Coldbox Proxy How Cool is This!

I had some CFGRID code I needed to implement into an existing ColdBox application. The grid run out of the box without any intervention from the ColdBox Framework. However it would be necessary for the CFGRID to access my service layer and properties injected from ColdSpring if I wanted it to take full advantage of the CB Framework. I assumed this would be a nightmare, I mean how to I get my AJAX grid to use the same reusable ColdBox and model code?

With ColdBox Proxy of course! The ColdBox proxy enables remote calls like AJAX to communicate with ColdBox and take advantage of all the goodies it has to offer, thanks ColdBox!

So how easy was it to get working? Very, it only took a few extra lines of code to work, really!

First I told my CFGRID to access the proxy directly and not the CFC.

   view plainprintabout
 bind="cfc:admin.coldboxproxy.getAllproducts({cfgridpage},
  {cfgridpagesize},
  {cfgridsortcolumn},
  {cfgridsortdirection})"

Next using the ColdBox proxy template already provided (which extends coldbox.system.extras.ColdboxProxy) I created a new function that works the same was as handlers in ColdBox.

   view plainprintabout
 <cffunction name="getAllproducts" output="false" access="remote" returntype="any" hint="Process a remote call and return data/objects back.">
  <cfargument name="page" type="numeric" required="yes">
  <cfargument name="pageSize" type="numeric" required="yes">
  <cfargument name="gridsortcolumn" type="string" required="no" default="">
  <cfargument name="gridsortdir" type="string" required="no" default="">
 
  <cfset var results = "">
  <cfset results = getBean("storeService").getAJAXProducts(page=#arguments.page#,                     pageSize=#arguments.pageSize#,
             gridsortcolumn=#arguments.gridsortcolumn#,
10              gridsortdir=#arguments.gridsortdir#) /
>

11  
12   <!--- Convert Query for Paging --->
13   <cfreturn QueryConvertForGrid(results,page,pageSize)>
14  </cffunction>

getBean("storeService") interact directly with the service layer. Once this was done I could then take advantage of my dependency injection framework and ColdBox features. How cool is that!

Learning ColdBox: Multiple Updates uisng a Object

My venture in ColdBox has been so far very enjoyable. It has really changed the way I plan my applications. My stumble in to using objects (correctly) has also brought with it some challenges and changed my approach to building maintainable and reusable applications.

So far my blog entries on ColdBox have mainly been on objects, validation and persistent, all straight forward when doing simple updating/creating/deleting actions.

Anyway, going back to challenges and objects, my first real stumbling block came a few weeks ago. How do I insert multiple records from data that comes from a form using a object?

I asked this question on both the ColdBox forums and CFTALK list. They all make it sound so simple, not sure they had this in mind.

My problem was as follows: when creating/updating a product I need to insert/update or delete multiple records for the product options based on what the user ticked or not ticked. So my first attempt worked that's a start right? here goes....

[More]

CF9 is here and another CF Builder Beta - check it out!

Everyone is already talking/writing about it, not wanting to miss out! ColdFusion 9 is released, prices are out! ColdFusion Builder not yet ready another beta is now available, check it out.

Persisting Values in ColdBox

I have never found a way to validate data I feel is 100% right for me, but I think I am getting close, let me explain.

I have a simple ColdBox 'view' containing my user form. This form is used to both create and update user's credentials.

   view plainprintabout
 user view
 
 <cfoutput>
  <fieldset>
  <div class="fm-req">
  <label for="firstname">First Name</label>
  <input id="firstname" name="firstname" type="text" class="text" value="#rc.bean.getfirstname()#" maxlength="15">
  </div>
  <div class="fm-req">
10   <label for="surname">Last Name</label>
11   <input id="surname" name="surname" type="text" class="text" maxlength="15" value="#rc.bean.getsurname()#">
12   </div>
13   <div class="fm-req">
14   <label for="email">Email Address</label>
15   <input id="email" name="email" type="text" class="text" maxlength="100" value="#rc.bean.getemail()#">
16   </div>
17   <div class="fm-req">
18   <label for="username">Username</label>
19   <input id="username" name="username" type="text" class="text" maxlength="12" value="#rc.bean.getusername()#">
20   </div>
21   <div class="fm-req">
22   <label for="password">Password</label>
23   <input id="password" name="password" type="password" class="text" maxlength="20" value="#variables.PasswordEncrypt#">
24   </div>
25   </fieldset>
26  </cfoutput>
   view plainprintabout
 example handler
 
 <!--- Edit User --->
 <cffunction name="editUser" access="public" returntype="void" output="false">
 <cfargument name="Event" type="coldbox.system.beans.requestContext">
  <cfscript>
      var rc = event.getCollection();// RC Reference
 
var userBean = variables.adminUsersService.createAdminUserBean(); //Create adminUserBean
 
     getPlugin('beanFactory').populateBean(userBean);//the magic bean machine
10  
     variables.adminUsersService.getUserByID(userBean);
11       rc.bean = userBean;
12       event.setValue("pageTitle","Edit System User");//Form H1 Title
13  
     event.setValue("formURL","/users/updateUser?adminId=#rc.adminId#");
14       event.setValue("buttonValue1","Update User");//H1 Title
15  
     runEvent(event='users.createUserTabs',private=true); // Create User Tabs
16  
     Event.setView("user/edit"); // Set the View To Display, after Logic
17  
</cfscript>
18  </cffunction>

I use one handler to create a new user and another to update, the only difference is the update handler pre populates the object from the database. So far simple stuff. Next I needed to validate my input. Again simple, I would submit to an intermediate handler that would validate my data against the object. However my dilemma is what to do if validation fails!

   view plainprintabout
 <!--- Validation --->
 <cffunction name="validation" access="public" returntype="void" output="false">
 <cfargument name="Event" type="coldbox.system.beans.requestContext">
  <cfscript>
      var rc = event.getCollection();// RC Reference
 
var userBean = variables.adminUsersService.createAdminUserBean(); //Create adminUserBean
 
getPlugin('beanFactory').populateBean(userBean);//the magic bean machine
 
    
      errors = userBean.validateUserALL();//Check For Validation Errors
10  
    
11       if NOTT ArrayLen(errors)){//No Validation Errors
12  
    
13           if ( variables.adminUsersService.updateUser(userBean)) {//Update Was OK
14  
             getPlugin("messagebox").setMessage("info", "User was successfully updated.");
15           }
16           else {//Could Not Update User Show Error Message
17  
             getPlugin("messagebox").setMessage("error", "Sorry, for some reason this user was not updated!");
18           }
19          
20       setNextEvent('users.overView'); // Set the Event To Run, After Logic
21  
     }//End Of No Validation Errors
22  
    
23       else {//We Have Validation Errors Show The User A Message
24  
getPlugin("messagebox").setMessage("error", "<b>The Following Validation Errors Occurred:</b><br />",errors);
25          
26   ///what to do here?
27  
        
28   }
29  
</cfscript>
30  </cffunction>

[More]

ColdBox and OO, Really?

Starting at the beginning I wanted push my knowledge a little more and continue with my venture into OO. Although I can recall most of the theory from my JAVA days at University, applying some of the concepts within ColdFusion does not seem to fit and in some instances proven difficult to get my head around.

I have come to the conclusion if I want to try and apply OO concepts to ColdFusion I must not think of OO and JAVA but an adaptation of the principles of OO reborn for ColdFusion (where did that come from? lol). Anyway with that said I had an eureka moment last night, ok, it came with help from the guys on the messages boards @ houseoffusion. I posted some code not fully understand the direction I needed to go in. Using ColdBox and ColdSpring I wanted to create a 'simple' example of a login which would help me better understand how to use objects containing 'getters' and 'setters'.

As it turns out its super easy in ColdBox, so easy infact I was looking for the hidden catch! Below is what I ended up with. It shows a function that is run in my handler to process a form post from a login page.

[More]

ColdBox and ColdSpring Hard Lessons

It has been a few weeks now of me getting to grips with ColdBox and ColdSpring. My question has been mainly on why I would use ColdSpring at all. Some will be glad to hear I am starting to see how ColdSpring helps with managing CFC's. I also just wanted to recommend Jason Dean's Blog. He has provided a very insightful step by step guide to using ColdBox and ColdSpring which has really helped me. I got it late, I know but if for some strange reason you have not read his series, do it, do it now!

The Hard Lesson

When I was creating my object i.e "userservice().init()" CF was throwing an error. It seemed ColdSpring knew nothing about my injected properties to the CFC, can you spot why? Well either ColdSpring or ColdBox (not sure which) handles the .init() it calls the constructor and passes in the correct argument without my help. So because I was trying to call the init() myself it was not being managed by ColdSpring. Simple, but it held me up for a long time. Because I always try and follow the best practice it never occurred to me this could be the culprit. A quick post on the ColdSpring user group and Brian Kotek quickly put me on the right track, thanks again.

[More]

NOSCRIPT and Google don't play nice!

A client recently reported to me a slight drop in traffic. After investigating I noticed that the text between the "noscript" tags were showing up in Goggle's search results. I also noticed in the keywords was the word "JavaScript". The site sells clothing and the keyword JavaScript is not one that I would except to be in the top 50 keywords the site makes an impression for.

[More]

More Entries

 

About Me

Glyn Jackson, 27 years old, MD and senior developer of a development firm based in Staffordshire called Newebia Ltd. Academic background in BSc Information System & Internet Commerce. Online marketing expert (EE Ranked) and .NET developer. Has been developing with ColdFusion for 5 years and loves it. "I am not a veteran in ColdFusion but I do work on challenging projects which help me learn more about ColdFusion and if I can contribute to the community in anyway then, it's all good!"

Recommends

  • ColdFusion