Ability to hold invalid data for integer fields on the form

Ability to hold invalid data for integer fields on the form

Old forum URL: forums.lhotka.net/forums/t/303.aspx


chrisb posted on Wednesday, June 07, 2006

I'm new to CSLA.net.  So, we allow our business objects to hold invalid data while the user is still editing the windows or web form.  What if a property should be int type?  Are you all making all properties strings to hold the invalid data?

That doesn't seem to model the business correctly.  Suppose I have a ShoppingCartItem class with Quantity field.  Quantity should be an int when used by the system. 

How is this typically done w/ CSLA?

Chris

 

ajj3085 replied on Wednesday, June 07, 2006

If you're using .Net 2.0, you can have a Nullable<int> and create some extender controls.

See http://www.lhotka.net/WeBlog/ExtendingControlsToHandleNullableTypes.aspx

chrisb replied on Wednesday, June 07, 2006

We're planning to move to .Net 2.0 and I'm reading the 2.0 version of Rocky's book. 

Nullable<int> is good for missing data.  But, what if the user types letters in a field that is to be numeric.  It would have to be stored as a string in the object, if I understand correctly and the object holds all the data. 

Am I correct in thinking that the object always holds a copy of the data in the form?

I guess I should clarify we're only doing webforms right now.

 

malloc1024 replied on Wednesday, June 07, 2006

You could create a textbox that accepts only integers.  You could also use an adapter to wrap your object.  The adapter would contain all string properties for the object that it wraps.

chrisb replied on Wednesday, June 07, 2006

Ok, the adapter sounds good.

Thanks for the help.

 

Brian Criswell replied on Wednesday, June 07, 2006

Why not just use the masked edit box?

chrisb replied on Wednesday, June 07, 2006

We're using WebForms so we must validate the submission even if we only allow numbers to be entered on the web page.

ajj3085 replied on Wednesday, June 07, 2006

A RegEx validator would seem to work for you than.

An advantage is that you don't need to write code for an adapeter class, and the validator will run server side as well, so it doesn't just rely on JavaScript.

Andy

chrisb replied on Wednesday, June 07, 2006

Thanks for the helpful suggestions.  We'll probably use validators.

 

Copyright (c) Marimer LLC