StrataFrame Forum

Custom fields don't show up in addbrokenrule list

http://forum.strataframe.net/Topic15881.aspx

By Marcel Heitlager - 4/24/2008

Hi,



I have some custom fields in a business object that are used to process a credit card payment. The information isn't stored in database but does need to be validated, and then passed on to a processor.



They are all required fields, and if skipped the error pointer shows up on the form. But when I do custom validation under CheckRulesOnCurrentRow the error pointer won't show up on the form. And I can't select the field from the Addbrokenrule list either.



How can the form identify which field had the error so the error pointer shows up?



Thanks,



Marcel



P.S. -- as a side thought, is it possible to use your business objects with custom fields only? (Nothing stored to database) It seems to have problems with two-way binding, especially when the custom fields are validated, because it can't find the tablename. Just wondering since now I don't save data now, but later however might need to. Just tried to get out of setting up database right now.Blush
By Trent L. Taylor - 4/25/2008

I have created a sample that shows how to do this as it has come up a time or two in the past.  All you really need to do is call the AddBrokenRule method with the weak-typed call:

Me.AddBrokenRule("MyCustomField","This field requires entry.")

But I created a sample that shows how to implement this and properly setup the BO as though it were created through the BO Mapper.  You can get that sample here: http://forum.strataframe.net/FindPost15885.aspx 

as a side thought, is it possible to use your business objects with custom fields only? (Nothing stored to database) It seems to have problems with two-way binding, especially when the custom fields are validated, because it can't find the tablename. Just wondering since now I don't save data now, but later however might need to. Just tried to get out of setting up database right now

Absolutely.  There is no difference between a custom property that is created through the BO Mapper and stored data to the server versus a custom property that just stores to a variable.  The only time that you will have a two-way issue is if you do not setup the property descriptors or change the binding on the control to which it is being bound.  You will see in the above sample that I overwrote the GetCustomBindablePropertyDescriptors method and added the custom property as a ReflectionPropertyDescriptor there.  This ensures that the binding gets properly setup when binding.

By Marcel Heitlager - 4/25/2008

OK, Thanks very much for the sample. Still got a problem though.



This is what I allready had:





Dim _ZipCode As String = ""

'''

''' Zip Code

''' _ZipCode

'''


BusinessFieldDisplayInEditor(), _

Description("Zip Code"), _

DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _

Public Property [ZipCode_cust]() As String

Get

Return _ZipCode

End Get

Set(ByVal value As String)

_ZipCode = value

End Set

End Property







I allready had the call to validate:





Private Sub CCBO_CheckRulesOnCurrentRow(ByVal e As MicroFour.StrataFrame.Business.CheckRulesEventArgs)



'--Validate zip code

If Len(Me.ZipCode_cust.Trim) > 0 Then

If Me.ZipCodeCheck(Me.ZipCode_cust.Trim) = False Then

Me.AddBrokenRule("zipcode_cust", "The Zip Code format in invalid.")

End If

End If



End Sub







I added what you had in your business object:





Protected Overrides Function GetCustomBindablePropertyDescriptors() As MicroFour.StrataFrame.Business.FieldPropertyDescriptor()

Return New FieldPropertyDescriptor() {New ReflectionPropertyDescriptor("ZipCode_cust", GetType(AES_PPM_BOL.CCBO))}

End Function





The code for the field on the web page is as follows:











Finally in the application base page I also had the following:



Private Sub Page_PreRender1(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender

Me.ErrorIcon = "images/brokenrule.gif"

End Sub







Eventhough the error line shows up, which it had from the beginning, the Brokenrule.gif doesn't show up at end of textbox when I do custom validation. It only shows up when the required field is empty (on same textbox). Am I missing something else?
By Marcel Heitlager - 4/25/2008

Sorry the line didn't show up on the web page. Apparently it's parsed out, so I'll add the important bits.



...BindingField="ZipCode_cust" BusinessObjectName="CCBO" IgnoreManageUIReadOnlyState="True" MaxLength="10">...(and ofcourse its as sfweb:textbox)



By Marcel Heitlager - 4/28/2008

PPS: Good Grief!  Also the _ZipCode and _ZipCode_Cust field are really the same. Doesn't change the result though. Blush
By Trent L. Taylor - 4/29/2008

OK...I am not sure what you are doing wrong through the posts here, so I added a web application to the previous sample I supplied and it all works as it should.  So you might be able to determine where your issue is through this sample.

http://forum.strataframe.net/FindPost15985.aspx