Converting Silverlight to HTML5 - What to do about validations

Converting Silverlight to HTML5 - What to do about validations

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


Savij posted on Monday, September 12, 2011

Hello All,

I am hoping someone here can help shed some light on using CSLA with today's hot idea of client-side web. I am going to try to convert an existing project from silverlight 4 to HTML5. I chose a small project I already have running but it is a complex project.

I have a question about how to handle validations. Currently the project generates a help desk type form for users to fill out when they are having issues. The form is dynamic in that it reads values from a database table and build the form for the user. So, if the user is having trouble sending email from their PC they would end up at a form asking for information about communications. They would choose email from a dropdown control. This would make the email address required. If they chose something else email might not be required. Some of the validations are client side and some are server side.

So in the new client-side project, lets say I generate an email help desk form as stated above. I might create a jquery validation to make sure the email is required. Also, if I needed to do a server side validation to check let say if a user account is locked in AD, I would need an Ajax/jquery call to the server. So it looks like my validations need to be moved to the client code so jquery works. But what about all the logic in CSLA. It works fine for Silverlight, but needs to be migrated to the client for HTML5?

How does this all work? I was under the impression that if I had a solid database and middle tier, that my client technology could be easily swapped. I have been able to change from Silverlight to Wpf and even web forms and win forms work well. When I move to a more client centric model it seems to collide with my design. Am I doing something wrong?

Thanks,

Jeff

tmg4340 replied on Monday, September 12, 2011

Savij

How does this all work? I was under the impression that if I had a solid database and middle tier, that my client technology could be easily swapped. I have been able to change from Silverlight to Wpf and even web forms and win forms work well. When I move to a more client centric model it seems to collide with my design. Am I doing something wrong?

Are you doing something wrong?  Nope... welcome to the world of frustration generated by going to the "hot idea" of HTML5/JS.  Smile

None of your .NET code will be worth a darn in the HTML-based, client-side web world.  That's been the case for quite some time, and it likely will continue to be.  It "works in web forms" probably because you were employing a "block mode" - i.e. let the folks enter what they want on the page, verify it all on the server when they hit "submit" (where your CSLA rules take over), and let the ASP.NET infrastructure do the work of highlighting/marking the bad data.  Something similar would be the case here as well, though you'd lose some of what the ASP.NET infrastructure takes care of for you.  If you want something more interactive, you'll either have to do a bunch of AJAX calls, or take all your CSLA validation code and translate it into client-side JS.  That would be copied code, BTW - you still obviously want to validate the data again on the server.

(And if you're going that route, I highly recommend you stick with some framework like jQuery validation - unless you really like writing a lot of cross-browser-compatible JavaScript...)

There is no tool I know of that takes .NET code and dynamically generates JS to stream to a browser.  I have heard of a couple of projects, but I don't think they were dynamic (i.e. run-time), and what little I remember indicated the results were less-than-ideal.  Given the complexity of the CSLA validation subsystem, I don't expect any project would do well.

If you look at Rocky's response to my post about the upcoming BUILD conference, you'll see his expectations for CSLA in an HTML5/JS world - primarily as a set of server-side services.  For client interactions, you're on your own, and likely will continue to be for some time.  Perhaps we're wrong.  But I wouldn't hold my breath.

HTH

- Scott

damianslee replied on Tuesday, May 22, 2012

Hi,
I've been looking at something similar the last week.    

With MVVM, and data binding in knockout.js or Kendo UI, the design/implementation of the single page web application is becoming very similar to how it is done in Silverlight.   I think that is what you meant by "client side web".  

So the web page never refreshes, it is like thicker client, withs comms in the background.   And instead of downloading silverlight .xap modules, its downloading .js modules.

I'm using Silverlight CSLA, looking to support mobile devices.

 

I'm thinking now, how hard is it to implement a csla.js with similar concepts to silverlight csla.   Which would have the BusinessBase, BusinessListBase, MobileFormater, data binding support...  

 

any one elses thoughts?

 

damian

damianslee replied on Tuesday, May 22, 2012

and also having the similar CSLA, N level Undo concepts in javascript, or BeginEdit, Apply, which would then push it to the data portal on the server.    Similar to how it works in silverlight CSLA.

JonnyBee replied on Wednesday, May 23, 2012

Another interesting part that may be possible to do is support for the RemoteAttribute to have javascript call into CSLA rule engine.

If you create business rules that do not rely on the business object (only uses InputPropertyValues) and CSLA offers a custom controller class that creates it's own RuleContext this should be possible.

Copyright (c) Marimer LLC