Bye Bye MS AJAX, Welcome JQuery

September 28, 2008 12:56 by ndibek

Finally the news that some of us in the ASP.NET MVC World have been secretly hoping for, has come true. Microsoft will ship JQuery as a part of ASP.NET inside Visual Studio - IntelliSense and all!  Not just that - it is to be the basis of any of their new Ajax UI widgets and elements they design in ASP.NET.

But why trust me, check from the source himself - Scott Guthrie:

http://weblogs.asp.net/scottgu/archive/2008/09/28/jquery-and-microsoft.aspx

For some of you that might have dropped out if this planet for the past year or two,  JQuery is a very powerful, yet simple JavaScript/Ajax framework that allows for a effective manipulation of Html elements without much of the script.  For details please check out:

http://www.jquery.com

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Implementing MVC Site using Csla and ExtJs - Part 3 - UI, ExtJs Customer DropDown List

September 10, 2008 09:32 by ndibek

This is the third part in series "Implementing MVC Site using Csla and ExtJs".  The first two parts can be found here:

Part 1 - Introduction 

Part 2 - Solution Structure 

 

In the previous 2 posts I mentioned decisions behind some of the technologies used in the demo as well as the file structure.

 If you remember I stated that url reguest like:

http://server/<Controler>/<Action>/<Parameter(s)>

is mapped into Controller.Action(Parameters...) call.

So lets take a look at the  our example - what happens when we click on Customer link:

As you can see the url follows the pattern we mentioned above.  So with the assumption from above we would presume that the CustomerController.List() method would be called.  Lets take a source code of that Action/Method to se how do we get to the view:

Where is the beef? List method seems to create some SelectList object, and then passes it to the method called View as a parameter.  Hmmm...  OK, method View probably results in View called List being rendered, and we are passing it SelectList for perhaps databinding...

Where is CSLA code?  Well, customerFactory is an instance of ReadOnlyListFactory class.  RetreiveAll() returns CustomerList instance which is ReadOnlyBase implemenation.  But why not use  CustomerList.RetreiveAll() - factory method?  Instead of using Factory Method design patern, we are using Abstract Factory, moving Create(), and Fetch() outside of our Csla BOs, for the purpose of easier Unit Testing.  I will explain the details of this in one of the future posts that has to explain the whole process of testing all of the app layers in Csla - which will probably be the best part of this demo.

For now, all we need to know is that there is AbstracBusinesstFactory class that defines following: 

 
and then the ReadOnlyListFactory.RetreiveAll() looks like this: 
 
and cutsomerFactory is instantiated with, in controller's constructor with:
 
var customerFactory = new ReadOnlyListFactory<CustomerList,CustomerInfo>();
 
Again all we care for now is that customerFactory.RetrieveAll() serves same purpose as customerList.RetriieveAll().
 
What does then SelectList object do?  It is used by Html.DropDownList() helper method of the MVC frameowrk (there are number of others) that renders html  <select>element for us.  All that SelectList does is it takes the IList implementation, like CustomerList, the other two parameters being Key Value (CustomerID)and  Display Value (CustomerName), for SelectList.
 
Lets now take a look at the Html source of the List.aspx: 
 
This actually is all of the Html that is in the List.aspx view, by the way.  I will explain later how the Order and OrderDetials grid "Magically" appear on it.
 
  

But wait, when I run the sample site the drop down I see has a different style from standard windows drop-down.  In addition to that we can see that the drop down has a type-ahead, kind of like Intelisense...

How come?  When I look at the html source very simple <select> element is rendered... 

Simply put this is where ExtJs comes in.  We have used ExtJs DropDown control, that simply can "inherit" from the Html element/instance, and extend it to implement some new functionality, like in this case.  What complicated JS did we have to write to do this, you might ask?
 
Well here it goes, this is all that is needed:
 
It appears that the script creates an Instance of Ext.form.ComboBox() class (I know, I know some of you might say: "But wait JS does not support classes".  Well ExtJs does, and so does JQuery, and Prototype - 3 most popular Ajax libraries on the planet). And it passes parameters, like typeAhead: true, and transform:'customerList'.  TypeAhead is obvious, but transform parameter is interesting.  It tells ExtJs.for.ComboBox class which html <select> element it needs to enhance/transform.  And that is all.  Oh, by the way there is an extra call that registers JS function refreshOrderGrid() to listen to "select" event on our drop-down, after the constructor.  That is the extCombo.addListener() call.
 
But Nermin, we should not use JavaScript, although that chunk of code looks cool.  Well then neither should folloing companies, all of which have sites built on top of ExtJs:
 
Adobe, Aetna, AIG, Alcatel-Lucent, Amazon.com, Best Buy, Boeing, Borland, CA, Canon, Capgemini, Cisco, CNN, Dow Jones & Co., EMC, Fidelity, General Electric, Hallmark, HP, HSBC, IBM, Mott MacDonald, NATO, NetApp, Nortel, Northrop Grumman, Panasonic, Pixar Animation Studios, Qualcomm, Inc., S&P, SAP, Siemens, Sony, Symantec
 
The difference between the JS that used to get us burned in the old ASP days and ExtJs is that ExtJs is extremely simple, it is used strictly for UI rendering - no business logic in JS, and allows for all of the modern language constructs in JS.  Building extension methods, overloads, custom expressions is easier in ExtJs than in C#.  And would you rather have unreadable and unmaintainable Java Script that some of the Web Forms control generate (that by the way is not compatible with all of the browsers, and can't be touched - it is generated), or would you use this easily extensible JavaScript  library directly.  Unlike Web Forms generated script this is easily manipulated for style, adding new features etc.  One can inherit from Ext.form.ComboBox class create its own extenions override existing methods behaviors.  Limit is only your cretivity.
 
This will just get more interesting in the next post when we discuss the "magically" appearing Order, and Order Detail grids. Grids that support everything that ASP.NET Web Forms GridView do and lot more.  And it is my humble hope that the article will prove to you that this results in by far simpler and easier to maintain code, that is easily testable, and more stable.
 
Source for this demo can be found at:

ExtJsDemo.zip (2.58 mb)

 
 
Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Implementing MVC Site using Csla and ExtJs - Part 2 - Solution Structure

September 10, 2008 06:34 by ndibek

This is the second article in "Implementing MVC Site using Csla and ExtJs".  There will be few more!  First one can be found at:

Part 1 - Introduction 

Unfortunately I have to get through this part and UI before I starttalking about my favorite parts TDD using MVC, Unit Testing in Csla,Design of the DAL in this example to support testability, and newfeatures of Csla 3.6 that support Unit Testing, like ObjectFactory. This part being UI, and how Csla BOs get rendered in MVC app that usesExtJs Ajax library.  Fortunate part about that though is that I hopemany of you will find the UI part to be something different and cool! 

So lets take a look at the ExtJsMvc solution (image on the left).  It includes 3 projects:

- ExtJsCslaDemo.Web (web site)

-  ExtJsCslaDemo.Web.Test (Unit tests library built on top of xUnit.net and RhinoMocks)

- Northwind.Data (Linq DAL + few classes that make testing a DAL breeze, on all on top of Northwind sample DB - attached in App_Datafolder)

 

Key to any Web MVC project are the following 3 folders:

- Controllers (controller classes are in this folder)

- Views (This folder contains all the Views/Pages to be rendered inthis application.  Views are grouped in Subfolders that hold the samename as a controller that is in charge of that view.  SO for example,you have a Customer subfolder of the Views folder that holds veiws thatthe CustomerController controls - a single veiw called List.aspx).

- Models (This is the place for your BOs that the Views will render- in this example, this is where I placed the Csla classes, butobviously for any solution that ).

 

As far as controllers our focus is going to be strictly onCustomerController, and OrderController.  HomeController is just thedefault one that gets created by the MVC project wizard, andAccountController is the one that takes care of security (login,changing passwords, etc).

 When it comes to views just notice that Customer Controller has oneview (List.aspx), while OrderController has no views in the Views/Orderfolder.  I will explain that part later in the UI section. 

 Source for this demo can be found at:

ExtJsDemo.zip (2.58 mb) 

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

An Issue with [HandleError] attribute in MVC and JQuery Ajax Load()

September 10, 2008 04:59 by ndibek

In CTP release 4 of MVC frameowrk for Asp.Net we have seen an introduction of [HandleError] attribute that can be assigned to a Controller class or individual Action methods.  It works great.  It captures any unhandled exceptions thrown by your code, and redirects to the default error Handling page/view Error.aspx that displays the exception detail.

The behavior can be fine-tuned further to have different pages for different exception types, or different Action methods.  But I have found one scenario where this attribute does not work, but could easiuly be addressed.

 Lets imagine a scenario where lets say you are builing a wizard.  Your primary view gets loaded as a container for wizard pages, and then you want each of your actual pages to be loaded inside a panel on your wizard.  Obviously you want to avoid post-backs, and you want to load those wizard pages as Ahax loaded partials.

In other words, Ajax call invokes a call on your controller that renders the Html for your page, and then your Ajax/JScript libary inserts that HTML at pre-destined place on your page.  Simple.

 Except that for this case, when error hapens inside the Controller that reneders my partial page I get nothing - no expected page and no error page either.  So what is the problem? Take a look at the source code of the HandleErrorAttribute.OnException() method (I used Reflector to get to it):

 

 
As you can see in the last 2 lines we clear the existing Response stream and return a StatusCode of 500.  Ajax libraries, like the one I used - JQuery, assume that the 500 is "Internal Server Error", and do not load/get the actual Html.
 
Solution to this problem:  I built my own HandleErrorAjaxPartial that inherits from HandleError and overrides the OnException() method, calling the base.OnException() and resetting StatusCode to OK (instead of 500).  Then all of the Controller actions that render wizard pages and are called from my Ajax code got marked with this new attribute, and now everything is fine.
 
Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Implementing MVC site using CSLA and ExtJs – Part 1 - Introduction

September 8, 2008 02:19 by ndibek

There are many folks who simply believe that one can’t develop a Test Driven MVC site using CSLA.NET.  Two just simply won’t work together!  CSLA.NET is just too tightly coupled! MVC and TDD require a specific DI architecture that simply cannot work with CSLA’a mobile objects.  Well we are here to disprove those assumptions.  In addition this will be the first step towards creating a CSLA standard bearer demo site in MVC – Project Tracker. 
This is going to be a multi-part post where each post will describe different parts of this MVC application, and different Csla integration points – Introduction – MVC part, Json UI, Unit Testing, and the choice of Repository Pattern for this demo. 

History

You can download the source here.   But before we go through the example what was my motivation behind this.  ASP.NET forms few years back represented one of the largest productivity increases in web development.  But soon we discovered that complex layouts require complex web controls and pages.  In addition to that none of the complex controls are easily extended, beyond simple tasks that are built into the control itself (style, and similar changes on a grid control, for example).  Awkward event model that was supposed to make it easier for Windows developer’s to migrate to web became another bottleneck.  The largest problem was that although we were coding ASP.NET web apps in .Net languages, our deployment target was still a combination of JavaScript/Html, the part that was almost completely abstracted away and hard to get to.
That abstraction was a reason for making any extensions to existing ASP.NET web controls and libraries harder.  For some controls like grid control for example, we did not even know what html is going to be rendered at run time.  It depended on browser type, version, time of the day,…  Worst of all when Ajax came out, technology that heavily depended on JavaScript/Html ASP.NET started falling behind some of the competitors.  For sure we got few little things like “Update Panels”, and little auto-completion fields (that somebody else built for us), but building anything yourself required JavaScript.  Not just that but integrating that JavaScript to run with the ASP.NET Server components was not the easiest thing in the world.

Concepts

That is where the idea of MVC came to life (actually few other competitors have had successful implementations before .Net, and even on .Net platform there was a Monorail platform that was available years before ASP.NET MVC).  Instead of having a web page/form respond to URL requests and Html form posts, they introduced a controller object.  And they came up with a simple mapping that allowed us to build rather simple public methods on the controller and map Html form values or URL query parameters to that method as parameters or directly onto a DTO object inside that method.  That separation resulted in easier program control flow from server to the web page, and breaking away from server side control model.  Pages became views, in charge of nothing but rendering a content and presenting it to the user, as well us posting changed data to the controller.  There was no more any complex business logic on the page itself, or complex "server event flow".

So if you would see a URL like:
http://server.com/Products/Edit/5,
that would map into a ProductController.Edit(5) action method.

I am not going to go though full introduction of MVC here.  You could go through the documentation/examples on following site:
http://asp.net/mvc
http://www.codeplex.com/aspnet
http://weblogs.asp.net/scottgu/archive/tags/MVC/default.aspx

Demo App

So this example (screen below) utilizes MVC Framework for ASP.NET and is built on top of CTP 5.

ExtJsDemo.zip (2.66 mb)

 

 At the back end of this demo is a copy of the Northwind database (found in App_Data folder).   It is a simple screen with 3 ReadOnlyList object.  On the left you will see a Drop Down with a list of customers.  Once a Customer is selected, we load a list of Orders for that Customer.  When selected, order displays its order details in the drop down below.  

All of the actions on this screen utilize Ajax calls.  Now for the choice of Ajax framework used here.  MS Ajax as it is built is out of questions.  It was built to support web form post back/callback model, which really cannot take advantage of the MVC model.  And simply put it is not very easy to use outside web forms.  AS far as MS MVC Ajax – MS folks have just started working on it for the latest CTP 5 release, and they are years behind ExtJs, Jquery, and other libraries.

That leaves us with JQuery and ExtJs (at least fro now).  However, one good thing about MVC framework, is that is built from scratch to be easily extensible, and to play well with any of the third part tools.  You will see in some of my future posts on this demo that I utlize xUnit.net and excellent unit test framework that drives the innovations in .Net unit testing world.  Not nUnit, or MSTest. Or for the same reason choice of RhinoMocks as the Dynamic Mocking framework.  For the same purpose in the future versios of this demo we will utilize StructureMap as a Dependency Injection framework instead of MS Unity.  All of these play very well with MVC and prove how extensible it is.  But enough about that - lets mov on with our demo solution.

There are conceptual differences with the JQuery and ExtJs.  JQuery is more focused on building dynamic html with its Ajax calls to the server, and dynamically inserting modifying parts of the page in response to Ajax action.  If for example you want to render a custom modal pop-up dialog inside the page, as a result of action on the page JQuery will submit action to the server – controller, that will then render the content of the dialog back to the page.  JQuery will then insert the dialog inside the modal frame control and display it.  That is more in line with traditional Ajax development.


My choice of the ExtJs had something to do with a lot of CSLA developers coming from the Windows world.  ExtJs actually provides us with the visual components/controls, like grids, drop downs, tabs, windows, etc…  This controls utilize JSon to submit modified data to the server, and receive the content they need to render from the server.  So instead of receiving a content of the grid control, for example, as a partial html page (table element), from the controller action, ExtJs grid actually receives what is called a JSon reader, and binds it to a sortable/ customizable grid control.


That way our server MVC model; actually utilizes more of a familiar control/event model on the client and I would actually say that for Windows developers this might be even easier migration path than the web forms.
In the next post I will be talking about UI portion of this demo, provide details of how we convert Csla objects into Json stream, send it from the Controller action and then utilize it within ExtJs Drop Down and Grid controls.  This post will mostly be about server side unit testing for controller and routes.  The fourth and final post should focus on the choice of Data Access Layer pattern – repository, and its integration into Csla code.

ExtJsDemo.zip (2.66 mb)

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Currently rated 4.7 by 3 people

  • Currently 4.666667/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

MVC Framework CTP 2

March 6, 2008 08:37 by ndibek
Jeffrey Palermo has just announced that the second release of Microsoft's ASP.NET MVC Framework is available now.  Download your copy from here.
Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Number of Scaffolding options grows in MVC for ASP.NET

January 20, 2008 06:51 by ndibek

As most of you already know Scott has announced that the Dynamic Data (see screencast) is going to have an MVC compatible version.

It appears that Rob Conery and SubSonic team have worked on MVC compatible version of SubSonic code-named Makai.

As you can see from the screen bellow, they implemented a ScaffoldController<T>, where T is a "model" portion of the MVC.  By inheriting from ScaffoldController<T> and declaring your model class, Makai framework implements all of the Create, Update, Delete, List actions for your controllers and generates dynamic views.  Therefore creating a prototype is a breeze.

I  do understand that a lot of MVC purist do tend to ignore the Scaffolding portion of the MVC, but it is a necessary evil.  MVC is a new technology in .Net world and it is hard to sell it to many IT managers.  But sometimees when they see how rapidly we develop a prototype  they might consider looking further.

Same as dynamic data, Makai generates a set of initial templates, that the list,edit and update views are using.  These templates can be overriden/modified and that is one way for us to get some flexibility in a defining the layout of the views in a prototype.

In addition to that, since Makai implementation is based on the controller, we simply can enrich the functionality by adding the new Actions/Views to our ScaffoldingController class.  This allows us to "evolve" the prototype into the product over time, instead of having to drop all of the prototype and start from scratch.

 For more details on Makai please visit Ron Conery's blog here.

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Scott shares some thoughts about MVC framework for ASP.NET on his web site

October 15, 2007 08:33 by ndibek

Well, it seems that man himself has spoken about details of this upcoming framework.  He has given us a timeline as well as what the framework encompasses.  What I find interesting is that it seems that Microsoft is not just building a "copy" of an open source project, replacing all of the Open Source libraries with their own, but actually building a framework that can interoperate with OpenSource libraries.

In other words, you are not limited to ObjectBuilder as an IoC container, you will be able to plug in Spring.Net, or Windsor, nor you are limited to MSTEST when it comes to unit testing.  I am truly surprised by these news from Microsoft.  Congratulations to Scott and his team.

Scott's post can be found at:

http://weblogs.asp.net/scottgu/archive/2007/10/14/asp-net-mvc-framework.aspx

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Scott Guthrie announces ASP.NET MVC framework at Alt.Net Conf

October 10, 2007 01:27 by ndibek

I have had several moments in my career where I was near a point of just simply giving up on MS and joining the "other side".  I remember the time few months before .Net 1.0 was released.  Java camp was leading the development world with innovations, while MS kept trying to persuade us that VB/COM was the way to go.  At that time I even joined the Java team at my company almost entirely making a switch.   

Then I was given an opportunity to review technologies for complete replacement of one of the ASP sites, project I was assigned to lead.  I evaluated obviously ASP, JSP, and soon to be released ASP.Net (learning C# at the same time).  And the thing that stroked me then was: "My God, sleeping giant has awaken!"  There was no question in my mind that C#/.Net was not a mere Java clone, but a well thought of framework and language that went one step further.  In addition there was nothing like ASP.NET available on the market.   

We started on the project the week .Net was released.  Completed it month ahead of schedule.  I stayed in MS camp.  

Another moment was just recently.  For any of you that read my blog you will know that I am really big fan of the Agile process and specifically Test Driven Development.  One of the problems with the TDD is being able to write/define tests/behaviors throughout your code including all layers of the application.  And we all know that sometimes UI code can prove virtually untestable.  That is where flavors of MVC/MVP patterns come in.  They help us solve that problem.  

MVC being doable in windows forms (using IoC, and frameworks like CAB), it was nearly impossible to accomplish it in the ASP.NET web development.  

That is when I saw my first demo of Ruby on Rails.  Everything that was missing, or done wrong in ASP.NET was implemented right in Ruby.  No huge configuration files, XML that "generates", code, source code versioning and schema migration are coordinated.  Schema is defined in one place only.  OR Mapping and the ActiveRecord pattern implemented flawlessly.  Ruby uses a true MVC implementation.  And it is all easy to learn and implement.  And productivity gained in developing, maintaining, migrating/updating, deploying these web apps is enormous.  

These concepts have been around for a few years.  Loads of Java folks and already some of the .Net folks are moving into Rails development.  Yet Microsoft stayed quiet about this, having virtually none of these features in upcoming VS2008.   

And right about time I am truly about to give up on MS altogether, I read this post from Jeffrey Palermo about an announcement of the MVC framework Scott Guthrie and his team are working on to be released as an add-on to the VS 2008.  Here are the goals of that project:

·  Natively support TDD model for controllers.

·  Provide ASPX (without viewstate or postbacks) as a view engine

·  Provide a hook for other view engines from MonoRail, etc.

·  Support IoC containers for controller creation and DI on the controllers

·  Provide complete control over URLs and navigation

·  Be pluggable throughout

·  Separation of concerns

·  Integrate nicely within ASP.NET

·  Support static as well as dynamic languages  

 

Folks familiar with MonoRail might say that there is all that built in the MonoRail project and lot more (ActiveRecord, Windsor, etc), and I agree with that.  But having all this come from Microsoft (with all of the visibility that comes with it), can only be a good thing.  I applaud Scott and his team - this is what I and bunch of the folks I know have been waiting for.  And yes, I think I will stay in MS camp for a while now.

 

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5