populate model

I have a model that I am trying to populate using populate model.

public void function save(){
var rc = event.getCollection();
rc.product = populateModel( model=productService.get(rc.productid),exclude=“category” );

}

The problem is I have a ton of fields that can be left null if need be like

publishedprice
cost
reducedprice
qty
etc…

If any of these fields are are left blank than I am getting errors. We allow these fields to be null in the database so I don’t want to param these values. Here is the error I am getting, can I not use populate if I have fields that meet these requirements?

Application Execution ExceptionError Type: BeanPopulator.PopulateBeanException : [N/A]

Error Messages: Error populating bean ..***.Product with argument PUBLISHEDPRICE of type class java.lang.String.

Not understanding

Luis F. Majano
President
Ortus Solutions, Corp
www.ortussolutions.com

ColdBox Platform: http://www.coldbox.org
Linked In: http://www.linkedin.com/pub/3/731/483
Blog: http://www.luismajano.com
IECFUG Manager: http://www.iecfug.com

Social: twitter.com/lmajano facebook.com/lmajano

I have some form fields

cost
publishedprice

When I call

populateModel( model=productService.get(rc.productid),exclude=“category” );

this populates the model from any matching variables in the request collection right? Well published price is an empty string which causes this error. If I were to default it to 0 than it works fine but I don’t want that because I want to keep nulls in the database.

Application Execution ExceptionError Type: BeanPopulator.PopulateBeanException : [N/A]

Error Messages: Error populating bean ..***.Product with argument PUBLISHEDPRICE of type class java.lang.String.

I think it may be because your setter in Product is expecting a
datatype of date and a blank string is a string. Do you get the same
error if you populate using the setters manually?

It is expecting a numeric value and getting a string. I guess I should look at the code for populate model but I would think if there is no value you shouldnt run the setter.

Hi Dan,

ColdBox can't know if you want a blank string or a null, they aren't
the same thing. I guess you could use an interceptor to remove any
keys from the rc collection that have an empty string, that way
ColdBox won't set the vale, however that would be an issue if you want
to set a value to null that previously had a value.

Sorry, that I can't give a better answer!

No problem, thanks John!

Hey Dan.

Have you found a solution for this. I know I need to implement
something like (JavaCast("null", '')). I'm just not sure where to do
it. Have you check this out:

http://www.dustinmartin.net/2011/04/using-a-populate-method-to-handle-nulls-empty-strings-and-numeric-values-with-cf9-orm/

Byron

Do you mind if I post the question on my blog? I can answer it this morning for you.

Thank You
Dan Vega
danvega@gmail.com
http://www.danvega.org/

Sure. Great.

Thanks.

Byron

I hope this helps

http://www.danvega.org/blog/2011/6/16/ColdBox-Bean-Populator-and-ORM

Thank You
Dan Vega
danvega@gmail.com
http://www.danvega.org/