[Coldbox 4.3.0] CF2016 - Cannot output MySQL data to a View

I created a model with Carrier, CarrierService and CarrierDAO like this:

/**

  • I am the Carrier bean object
    */

component accessors=“true”{

// properties

property name=“car_carrier_cd”;
property name=“car_carrier_nm”;
property name=“car_transport_mode”;
property name=“car_awb_prefix”;

// validation

this.constraints = {

car_carrier_cd = {required=true},
car_carrier_nm = {required=true},
car_carrier_mode = {required=true},
car_awb_prefix = {required=false}

};

function init(){
return this;
}

}

/**

  • I am the CarrierService Model Object
    */
    component singleton accessors=“true”{

// Dependency Injection

property name=“dao” inject=“CarrierDAO”;
property name=“log” inject=“logbox:logger:{this}”;
property name=“populator” inject=“wirebox:populator”;
property name=“wirebox” inject=“wirebox”;

function init(){
return this;

}

/**

  • Get all carriers as an array of objects or query
    */

function list(boolean asQuery=false){

var q = dao.getAllCarriers();

log.info(“Retrieve all carriers”, q.recordcount);

if( asQuery ){ return q; }

// convert to objects

var carriers = [];
for(var x=1; x lte q.recordcount; x++){

arrayAppend( carriers, populator.populateFromQuery( wirebox.getInstance(“Carrier”), q, x ) );

}

return carriers;

}

/**

  • I am the CarrierDAO Model Object
    */

component singleton accessors=“true”{

// Dependency Injection
property name=“dsn” inject=“coldbox:datasource:g2g”;

/**

  • Constructor
    */

function init(){

return this;

}

query function getAllCarriers(){

var q = new Query(datasource="#dsn.name#",sql=“SELECT * FROM tab_carriers”);
return q.execute().getResult();

}

To test the MySQL connection, I could properly list the data from th tab_carriers table above and output
the contents of the table in an array object using writeDump(prc.aCarriers) in the controller below:

/**

  • I am the carriers handler
    */

component{

// Dependency Injection
property name=“carrierService” inject=“CarrierService”;

function index(event,rc,prc){

// Get all carriers

prc.aCarriers = CarrierService.list();
//writeDump(prc.aCarriers);
event.setView(“carriers/index”);

}

However, when I want to display the same array output in the View carriers/index like this:

carriers.index

#html.table( data = prc.aCarriers, class=“table table-striped” )#

I get a java.lang.NullPointerException, apparently triggered by the HTMLhelper.cfc.
Any suggestions as to where could be the issue considering the fact that:

  • I am not using ORM
  • Coldbox was re-inited
  • I assume that the models and the datasource are fine since I could pull the data from the MySQL table
    into writeDump(prc.aCarriers).

Can you copy the actual stack trace of the error into a Gist or something. Your stack trace cuts off the most useful part and only shows part of the tag context.

Thanks!

~Brad

ColdBox/CommandBox Developer Advocate
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

Hi Brad,

Attached is the complete stack trace in a pdf document.

Philippe

carriers.pdf (106 KB)

That error is likely due to not having ORM enabled. Luis used an ORM-specific function in there: EntityToQuery()
Now, I don’t know why you’re getting an NPE and not some polite error telling you that ORM isn’t enabled, but that’s probably just a bug in ColdFusion.

I’m not sure if Luis intended that HTML Helper function to be usable without ORM enabled. You’d have to ask him.

Thanks!

~Brad

ColdBox/CommandBox Developer Advocate
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

Hi Brad,

Thank you for the feedback. I used the code that was in the Coldbox full documentation (Solo case without ORM). I am not going to use ORM at that stage and instead shall work around the EntityToQuery() function with some non ORM equivalent.

Philippe

No worries… I found a workaround. In the CarrierService component, I changed the boolean argument to true in the function list(boolean asQuery=true), so as to return a query instead of an array. Then, the HTMLHelper.cfc does not complain any more and my table data are properly rendered to the View.

Philippe