LivePersistence="false" and FormView Empty

Posts   
 
    
av_harris
User
Posts: 17
Joined: 23-Apr-2007
# Posted on: 27-Apr-2007 22:31:11   

I'm trying to utilize the PerformWork event and set LivePersistence="false". However, this caused my form to disappear. I realize that this is probably because of an error somewhere in my code but I just can't seem to find it.

When the setting is true, the record I want to edit appears and I can makes changes and save them. I do have a "FilterToUse" property set but even when I remove this logic from the page load event, I still get the blank form. I should point out that the screen loads but the form isn't visible.

Here is my very generic datasource:


    <llblgenpro:LLBLGenProDataSource ID="LLBLGenProDataSource1" runat="server" 
                                    DataContainerType="EntityCollection" 
                                    EntityCollectionTypeName="OHA.CollectionClasses.OhaNameCollection, OHA">
    </llblgenpro:LLBLGenProDataSource>


I've been pouring over the forum looking for something similar but I seem to be the only one with the problem.

I'm using the self-service template with VB.

BTW, one of the primary reasons for using LLBLGenPro was that you were the only one that generated VB code. It would be really useful ifin your responses to questions in the forum), you try to provide VB examples in addition to C#.

Thanks.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 28-Apr-2007 04:24:25   

When you use LivePersistence=false, you should point PerformWork, PerformSelect, and **PerformGetDbCount **events handlers. Do you have a PerformSelect handler? somthing like:

Protected Sub dsProduct_PerformSelect(ByVal sender As Object, ByVal e As SD.LLBLGen.Pro.ORMSupportClasses.PerformSelectEventArgs2) Handles dsProduct.PerformSelect
        
     Dim adapter As DataAccessAdapter = new DataAccessAdapter()
     adapter.FetchEntityCollection(e.ContainedCollection, e.Filter, e.MaxNumberOfItemsToReturn, Sorter, e.PrefetchPath, e.PageNumber, e.PageSize)
            
End Sub

About VB samples, all the LLBLGenPro documentation has exampleas in C# as well VB. simple_smile

David Elizondo | LLBLGen Support Team
av_harris
User
Posts: 17
Joined: 23-Apr-2007
# Posted on: 28-Apr-2007 05:04:53   

Thanks for the prompt response.

I did not have events in either of the other 2 handlers. I tried pasting your code but I'm not using the adapter method so it doesn't work. Just to be sure that I had something, I put in a messagebox. The message did pop up during the PerformSelect event so I know that the handler is working. However, my form was still blank.

Then, I tried inserting my filter code (from the page load event) in here but I still got nothing.

    Protected Sub test2(ByVal sender As Object, ByVal e As SD.LLBLGen.Pro.ORMSupportClasses.PerformSelectEventArgs) Handles LLBLGenProDataSource1.PerformSelect
        Dim PredEx As IPredicateExpression = New PredicateExpression

        PredEx.Add(OhaNameFields.PkId = Request.QueryString("pkId"))
        Me.LLBLGenProDataSource1.FilterToUse = PredEx
    End Sub

Can you show me some specific code that I can try for the self-service method?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 28-Apr-2007 06:08:56   

Can you show me some specific code that I can try for the self-service method?

My apologies, here is the method handler for selfServicing:

protected void LLBLGenProDataSource1_PerformSelect(object sender, SD.LLBLGen.Pro.ORMSupportClasses.PerformSelectEventArgs e)
    {
        e.ContainedCollection.GetMulti(e.Filter, 0, e.Sorter, e.Relations, e.PrefetchPath);
    }
David Elizondo | LLBLGen Support Team
av_harris
User
Posts: 17
Joined: 23-Apr-2007
# Posted on: 28-Apr-2007 22:51:33   

Thanks again. I was able to make the form load with LivePresence false.

For those coding in VB, here is what I eneded up with:


    Protected Sub test2(ByVal sender As Object, ByVal e As  SD.LLBLGen.Pro.ORMSupportClasses.PerformSelectEventArgs) Handles LLBLGenProDataSource1.PerformSelect
        Dim PredEx As IPredicateExpression = New PredicateExpression

        PredEx.Add(<Entity>Fields.PkId = Request.QueryString("<passed query string"))

        e.ContainedCollection.GetMulti(PredEx, 0, e.Sorter, e.Relations, e.PrefetchPath)

    End Sub

I really appreciate your help on this.

The fact that support is available this quickly is great. However, I'd rather have not had to go through these exchanges to get an answer to something this simple. Can I please point out that THIS is the type of situation where examples (in the manual) would be very helpful. Also, I cannot stress strongly enough that every example must be provided in both VB & C#.

From reading many posts, I know that the philisophy is not to teach .NET but you folks must understand that for many people, LLBLGen is just one more piece of new software that has to be learned. Most of us haven't memorized the entire .NET class structure which can lead to all sorts of misadventures when I'm handed a snippet of code with no clue as to which namespace to import. I know that users ask all sorts of stupid questions but very few actually want to.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 29-Apr-2007 20:59:33   

av_harris wrote:

Thanks again. I was able to make the form load with LivePresence false.

For those coding in VB, here is what I eneded up with:


    Protected Sub test2(ByVal sender As Object, ByVal e As  SD.LLBLGen.Pro.ORMSupportClasses.PerformSelectEventArgs) Handles LLBLGenProDataSource1.PerformSelect
        Dim PredEx As IPredicateExpression = New PredicateExpression

        PredEx.Add(<Entity>Fields.PkId = Request.QueryString("<passed query string"))

        e.ContainedCollection.GetMulti(PredEx, 0, e.Sorter, e.Relations, e.PrefetchPath)

    End Sub

Thanks. I'm glad in solving your questions.

av_harris wrote:

I really appreciate your help on this.

The fact that support is available this quickly is great. However, I'd rather have not had to go through these exchanges to get an answer to something this simple. Can I please point out that THIS is the type of situation where examples (in the manual) would be very helpful. Also, I cannot stress strongly enough that every example must be provided in both VB & C#.

From reading many posts, I know that the philisophy is not to teach .NET but you folks must understand that for many people, LLBLGen is just one more piece of new software that has to be learned. Most of us haven't memorized the entire .NET class structure which can lead to all sorts of misadventures when I'm handed a snippet of code with no clue as to which namespace to import. I know that users ask all sorts of stupid questions but very few actually want to.

The LLBLGenPro Help offers always snippets both in C# and VB. The LLBLGenPro Reference Manual is a great place to be aware of the LLBLGenPro infrastructure, namespaces, overloads, etc. The forums is also a great place to find examples, cases, scenarios. There are a lot of great successful projects we have learned. At http://www.llblgen.com there are a lot of examples and videos, third party tools, etc. Some of those in C# but there are many tools that migrate to VB. However, thanks for your appreciation. We always are finding better ways to support you. I am doing support and I've a lot of examples and I would want to share to the public.

David Elizondo | LLBLGen Support Team
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 01-May-2007 11:05:02   

av_harris wrote:

The fact that support is available this quickly is great. However, I'd rather have not had to go through these exchanges to get an answer to something this simple. Can I please point out that THIS is the type of situation where examples (in the manual) would be very helpful. Also, I cannot stress strongly enough that every example must be provided in both VB & C#.

We try to get examples in both languages, but frankly that's not always possible. For example we released this forum's sourcecode as a big example (http://www.llblgen.com/hnd ). It's in C# and we're not going to port it to VB.NET.

From reading many posts, I know that the philisophy is not to teach .NET but you folks must understand that for many people, LLBLGen is just one more piece of new software that has to be learned. Most of us haven't memorized the entire .NET class structure which can lead to all sorts of misadventures when I'm handed a snippet of code with no clue as to which namespace to import. I know that users ask all sorts of stupid questions but very few actually want to.

We're not expecting people to know the complete BCL, we don't either. What we can't do is teach people ASP.NET first, as that's not what LLBLGen Pro is all about. So to use a datasource control, any datasource control, for example in ASP.NET you do have to know a little about ASP.NET. Not every page event or page life cycle, but the basics have to be clear, otherwise creating a webpage is a bit of a struggle anyway, and if something goes wrong, WE are asked why something went wrong while it's not always our fault, simply because something else in the ASP.NET code went wrong.

It's a difficult decision to make and we hope we give as much information as possible. Our manual is 400+ pages thick, though there's still a lot of room for improvement and we do realize that and with each upgrade we try to enhance the documentation as much as possible.

Frans Bouma | Lead developer LLBLGen Pro
av_harris
User
Posts: 17
Joined: 23-Apr-2007
# Posted on: 01-May-2007 12:56:18   

One last comment.

I've been searching the manual, forum, and other online sources for help with entity validation. I'm almost to the point of being able to actually run some code but I've been working on this for at least 4 days solid. I even did text searches of the source code for all of your downloadable examples and I couldn't find any instances where custom validation is taking place.

I can't imagine that most people don't want to do some form of complex validation for comparing form data with other elements on the page or against a table. Would it be possible for you folks to post all the code for one simple form containing a few textboxes that demonstrates how custom validation is implemented? I come from a PHP background where I completely ignored the OO aspects and just made the pages work. I'd like to implement validation within the OO framework but I just can't seem to get past the basics of .NET. One working sample would go a long way towards self-sufficiency!

btw, I found a good online C#-VB converter so the problem of C# examples not making sense has been eliminated.

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 02-May-2007 08:43:05   

I can't imagine that most people don't want to do some form of complex validation for comparing form data with other elements on the page or against a table. Would it be possible for you folks to post all the code for one simple form containing a few textboxes that demonstrates how custom validation is implemented?

Would you please explain what is it that you want to validate?

Coz there are EnitityValidation and FieldValidations as explained in the manual, and there is also UI validation (with .NET Validation controls, to validate the User input upfront).

av_harris
User
Posts: 17
Joined: 23-Apr-2007
# Posted on: 02-May-2007 09:30:44   

I'd like to validate user input boxes on a form. Not just their values (which I have managed to figure out) but to be able to compare them to each other. For example, I will have a home and mailing address and I want to ensure that at least one of them has an entry.

I read the manual and see that this is possible. However, I am clueless when it comes to determining if I need to do the validation from PerformWork or if I only need to add my logic in ValidateEntityBeforeSave. Unfortunately, I also can't seem to grasp how to properly reference/ partial class LLBL functions becasue even when I see the function in the class, Intellisense/ VS 2005 is reporting an error of some kind. Usually of the "mustinherit" variety.

I certainly don't want or expect you to code for me but a working example of the kind of validation I mentioned above would at least show me one way that I could piece it together for myself.

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 02-May-2007 10:09:58   

I am clueless when it comes to determining if I need to do the validation from PerformWork or if I only need to add my logic in ValidateEntityBeforeSave.

If it's a common-scenario validation for that entity (is required in all cases), then you should put it in OnValidateEntityBeforeSave. Otherwise if it's just needed for this form, then you might put it in the PerformWork event handler.

av_harris
User
Posts: 17
Joined: 23-Apr-2007
# Posted on: 02-May-2007 23:18:54   

Before I spin my wheels too much longer, perhaps I can provide you with some specifics and you could point me in the right direction. Here is some code from my formview:


    <llblgenpro:LLBLGenProDataSource ID="LLBLGenProDataSource1" runat="server" 
                                    DataContainerType="EntityCollection" 
                                    EntityCollectionTypeName="OHA.CollectionClasses.OhaNameCollection, OHA" LivePersistence="False">
    </llblgenpro:LLBLGenProDataSource>
    <asp:FormView ID="FormView1" runat="server" DataKeyNames="PkId" 
                    DataSourceID="LLBLGenProDataSource1" DefaultMode="Edit">
        <EditItemTemplate>
        <table>
...many textboxes truncated
                <asp:TextBox Width="80px" ID="HAddrNoTextBox" runat="server" Text='<%# Bind("HAddrNo") %>'>
                </asp:TextBox>

...more code truncated

                <asp:TextBox Width="200px" ID="MAddrStreetTextBox" runat="server" Text='<%# Bind("MAddrStreet") %>'>
                </asp:TextBox>

I have a PerformWork event handler declared and I've tested to see if it fires (it does).

Could you provide me with a sample of the VB code that I need in the handler? What I need is to see how the textbox values are referenced and how to initiate the save if the values meet my criteria or how to postback and inform the user that there are errors.

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 03-May-2007 10:21:21   

You can access a text box in a FormView by using the FindControl method as follows:

TextBox tb = (TextBox)FormView1.FindControl("HAddrNoTextBox");

To access the Text within:

String text1 = ((TextBox)FormView1.FindControl("HAddrNoTextBox")).Text
av_harris
User
Posts: 17
Joined: 23-Apr-2007
# Posted on: 04-May-2007 10:23:18   

OK. I'm able to access the values in my textboxes and I can call a messagebox so I know the criteria is being evaluated properly.

I spent most of the day trying to figure out how to stop the save process and/or explicitly commit the changes to the database. I read and re-read the IDataError section but it still doesn't seem to make sense. I was especially confused with the forum posting (http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=6259&HighLight=1) that had a final entry which linked back to the first page of the very same forum item! If the IdataError interface is as problematic as that post suggests, then what is the recommended method for trapping/throwing data entry errors?

Now that I have a registered version, I saw the ASP.NET 2.0 GUI template. Should I be using that?

I really like your product and want to make it work. I look forward to your advice.

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 04-May-2007 16:38:11   

I removed that un-needed link.

Have you tried to use an error provider control?

I think the following thread might be useful: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=8593

You may also use a label control to displpay the error, which can be set from the PerformWork event, and don't commit the UOW object if the data was not valid.

av_harris
User
Posts: 17
Joined: 23-Apr-2007
# Posted on: 04-May-2007 20:46:05   

Thanks. I will see if I can make sense of the Error Provider.

I'm still not clear on how to do the following:

  • commit the changes if validation is successful (right now, it looks like the data is being saved immediately after PerformWork finishes)
  • stop the editing process to allow the error message to display

I know that I have the LLBL datasource control that is bound to my entity class. I didn't see any save or update method associated with the control. I also know that the PerformWork event is firing and that I somehow need to cause the event to "fail".

Can you help me to understand this process?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 05-May-2007 05:15:09   

Entity field validation, which is triggered by SetNewFieldValue(), sets the field error if an exception occurs or when the custom field validator fails. The error message is appended to an existing message.

LLBLGenProDataSource knows how to save/update, however you can use PerformWork to custom the save/update process. If an exception trows (fieldValidation error, entityValidation error, other erros) you can catch here and manage the error. You can also bind the error message to some controls. That is what you want?

David Elizondo | LLBLGen Support Team
av_harris
User
Posts: 17
Joined: 23-Apr-2007
# Posted on: 06-May-2007 01:17:07   

LLBLGenProDataSource knows how to save/update, however you can use PerformWork to custom the save/update process. If an exception trows (fieldValidation error, entityValidation error, other erros) you can catch here and manage the error. You can also bind the error message to some controls. That is what you want?

Yes. That is basically what I want to do. I have the PerformWork event handler but I need to know how to throw errors that can be picked up by the ValidationSummary control and both cancel the save and/or continue it through the LLBLGenProDataSource control. I think the area that is most unclear to me is whether I'm using an entity or not. I know the control is bound to my entity but am I supposed to issue my saves/cancel through the entity or the LLBLGenProDataSource control? If possible, I'd really appreacite an example in VB. Thanks.

Jessynoo avatar
Jessynoo
Support Team
Posts: 296
Joined: 19-Aug-2004
# Posted on: 07-May-2007 16:08:43   

Hi,

The PerformWork handler gives you access to the unit of work to persist.

From that point, you can either browse the entities from your uow and handle the persistence / validation individually, or maybe use a transaction and persist the unit of work as a whole (uow.Commit(adapter, false)) in a try with commit vs. catch+rollback+exception handling

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 08-May-2007 10:16:21   

I just attached an example project in VB.Net, SelfServicing, using Northwind and LLBLGenPro v2.0.

I create a _CustomersValidator _that verify that the _Phone _field and _Fax _field are different among themselves. In a _CustomersEntity _partial class I override the _CreateValidator _method so return an instance of my custom _CustomersValidator _class.

At _PerformWork _event I Catch the _ORMEntityValidationException _and show the message in an error label.

Hope helpful.

David Elizondo | LLBLGen Support Team
av_harris
User
Posts: 17
Joined: 23-Apr-2007
# Posted on: 08-May-2007 21:11:37   

David,

This was incredibly helpful!

I see that this sample came from the manual but having working code to look at and follow along with is much, much better than any amount of theory and/or manual-quoting.

I think I have one last validation question: Is there a more elegant way to handle multiple data entry errors? Especially since this is taking place in the step immediately before save, I would like to be able to throw multiple error messages and display them, preferably utilizing the ValidationSummary feature. I can't imagine that my users are the only ones who screw-up more than once on one page! It would make sense to be able to keep adding messages to a "collection" of some sort.

Anyone got suggestions for this?

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 09-May-2007 10:30:34   

I think I have one last validation question: Is there a more elegant way to handle multiple data entry errors? Especially since this is taking place in the step immediately before save, I would like to be able to throw multiple error messages and display them, preferably utilizing the ValidationSummary feature.

As far as I know, the ValidationSummary contril is used with Validation controls on a webPage to summerize the errors that appear within those controls, and these are user input validations, which can be used also in you case.

But the code posted by David was using entityValidation technique rather than User Inputs validation.

So for the posted example you can formulate the exception message as you want in the validation function. According to the in-vlaid fields. Which you would catch later to display in a label control.

av_harris
User
Posts: 17
Joined: 23-Apr-2007
# Posted on: 10-May-2007 22:48:51   

Thanks again for all the help. Using the sample, I now have a working version for my own code.

I have a couple of questions about the sample. Here's the particular section:

        Public Overrides Sub ValidateEntityBeforeSave(ByVal involvedEntity As IEntityCore)
            Dim toValidate As CustomersEntity = CType(involvedEntity, CustomersEntity)
            If toValidate.Fax = toValidate.Phone Then
                toValidate.SetEntityError("Phone and Fax can't be the same.")
                Throw New ORMEntityValidationException("Phone and Fax can't be the same.", toValidate)
            End If

            MyBase.ValidateEntityBeforeSave(involvedEntity)
        End Sub

1) What does the SetEntityError line do? I don't see where the message is being used.

2) I noticed that ORMEntityValidationException is serializable. Does this mean that if I send multiple mesages, they're being stored as a list I can iterate through? If so, can you show me how I would do this?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 12-May-2007 09:42:47   

1) What does the SetEntityError line do? I don't see where the message is being used.

Well, in this example I shouldn't use the _SetEntityError _ (simple_smile ) as I never used it further. The exception gave me the info to show the message to the user.

2) I noticed that ORMEntityValidationException is serializable. Does this mean that if I send multiple mesages, they're being stored as a list I can iterate through? If so, can you show me how I would do this?

Although they are serializables. they don't be saved in a list. However you can append the error messages to a string message and throw ORMEntityValidationException with this one string. Then at GUI you'll obtain a full descriptive message of all errors encountered.

David Elizondo | LLBLGen Support Team