populateFromQuery

Is there a replacement for populateFromQuery? I’d like to populate an instantiated bean from a query.

Sorry, for the dumb question but I can’t find an example in the docs.

LOCAL.myQuery=myService.myFunction(somevalue); //I have my model injected in my handler and I’m using it to create a query of data

LOCAL.myBean=populateModel(‘myBean’); //I grab from some data from the form and put in a bean

Now, I have some data in LOCAL.myQuery that I want to populate in the bean. Sorry, but I do this besides using individual setters?

I see this http://wiki.coldbox.org/wiki/WireBox.cfm#populateFromQuery

No examples and I’m at a loss.

Thanks.

Jonathan

You just need to inject the wirebox object populator into your cfc and then use that function. Something like:

property name=“pop” inject=“wirebox:populator”;

then:
pop.populateFromQuery(‘myBean’);

that’s it!

sorry - forgot to add the query! should have said:

pop.populateFromQuery(‘myBean’,LOCAL.myQuery);

Thanks for the help. I’m off and running.

Now that I've used the populateFromQuery, I'm trying to learn
populateFromXML. In this case my XML is pretty simple.

<recipients><recipient>blah@gmail.com</recipient><recipient>blah@blah.com
</recipient></recipients>

I'm looking at the wiki but due to lack of examples, I struggle.

http://wiki.coldbox.org/wiki/WireBox.cfm#populateFromXML

My sample code:

LOCAL.bounce=emailService.getBounceList(); //API call that gets me XML

LOCAL.myArray=arrayNew(1); //create an array to populate

LOCAL.result=populator.populateFromXML(target=rc.myArray,xml=
rc.bounce.filecontent,root='recipients'); //populate the array right??

Thanks for any advice.

Jonathan

It looks like that method has some requirements for how the XMl should be structured. I would just look at the code to see how it works. Here is the meat of it:

// iterate and build struct of data
childElements = arguments.xml[arguments.root].XMLChildren;
for(x=1; x lte arrayLen(childElements); x=x+1){
arguments.memento[ childElements[x].XMLName ] = trim(childElements[x].XMLText);
}

return populateFromStruct(argumentCollection=arguments);

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

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

Corrected code. Maybe I can’t use an array? So I try a struct.

LOCAL.bounce=emailService.getBounceList();

LOCAL.myStruct=structNew();

LOCAL.result=populator.populateFromXML(target=LOCAL.myStruct,xml=LOCAL.bounce.filecontent,root=‘recipients’);