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

22 views
Skip to first unread message

Philippe Sambor

unread,
Jan 8, 2018, 11:38:14 PM1/8/18
to ColdBox Platform
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:

<cfoutput>
<h1>carriers.index</h1>

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

</cfoutput>

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).
myData.png
nullpointer error.png

br...@bradwood.com

unread,
Jan 8, 2018, 11:55:46 PM1/8/18
to col...@googlegroups.com
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: br...@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com 
 
 
--------- Original Message ---------
--
--
You received this message because you are subscribed to the Google Groups "ColdBox Platform" group.
For News, visit http://blog.coldbox.org
For Documentation, visit http://wiki.coldbox.org
For Bug Reports, visit https://ortussolutions.atlassian.net/browse/COLDBOX
---
You received this message because you are subscribed to the Google Groups "ColdBox Platform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to coldbox+u...@googlegroups.com.
To post to this group, send email to col...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/coldbox/8f14628e-f579-4b94-a51c-699a438057c7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Philippe Sambor

unread,
Jan 9, 2018, 4:42:14 AM1/9/18
to ColdBox Platform
Hi Brad,

Attached is the complete stack trace in a pdf document.

Philippe
carriers.pdf

br...@bradwood.com

unread,
Jan 9, 2018, 10:39:50 AM1/9/18
to col...@googlegroups.com
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.
--------- Original Message ---------

Philippe Sambor

unread,
Jan 9, 2018, 8:28:01 PM1/9/18
to ColdBox Platform
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 

Philippe Sambor

unread,
Jan 9, 2018, 9:18:30 PM1/9/18
to ColdBox Platform
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
Reply all
Reply to author
Forward
0 new messages