Microsoft MVC – First Attempt

January 22, 2009

I finally found some useful web pages that explained MVC in a way I could understand.

This is where I started. Scott Guthrie is one of several great Microsoft bloggers. I tried this code, but it is badly out of date. But the descriptions are excellent and most instructive.
ASP.NET MVC Framework (Part 1)

Phil Haack had an interesting summary of MVC/MVP:
Everything You Wanted To Know About MVC and MVP But Were Afraid To Ask

Dino Esposito also has some interesting comments that help illuminate the MVC topic:
Architectural View of the ASP.NET MVC Framework.

The MVC tutorials were useful too, once I understood what these guys were all talking about. I’ve referred to these tutorials several times.
ASP.NET MVC Tutorials

Here’s the technical docs on MVC. They’re a little lean, but still useful.
ASP.NET Model-View-Controller Applications

Lastly, a couple of the Telerik bloggers are great too.
Atanas Korchev has a working sample app that uses the RadGrid and other RadControls to display data in a sample MVC forum application. His blog entry has the download at:
ASP.NET Ajax Controls in ASP.NET MVC – Announcing the sample application
Vladimir Enchev also has some interesting posts on MVC. Particularly this one:
Telerik RadControls in Microsoft ASP.NET MVC

So, from all of this, I was able to piece together a working MVC sample.

It doesn’t do much, just retrieves a few rows from a table and displays them in a Telerik RadGrid. There’s even a unit test to make sure the Controller returns the rows from the model that I expected it to. I’ll post some code on this soon.


Seasons Change… Greener Pastures?

January 22, 2009

After spending several months figuring out how to automate the build of a Java app in using Maven, CruiseControl and myriad other tools, I took a job where I can return to working with Microsoft technology. However, little did I know, the greener grass wasn’t mowed and disguised the morass that is web development anyway. So, instead of learning Java, I have had to learn ASP.Net, Javascript and AJAX, Telerik RadControls for Ajax and more. It turns out that with ViewState, Session State and a Stateless environment, everything gets confused. Add in Server side, Client side, Postbacks, AsyncCallBacks and it’s a royal mess.

Having recently having my eyes opened to Open Source, the first area I pursued was the Data Layer. I started with NHibernate, but it turned out to be a bad fit. SubSonic was MUCH better, but it didn’t support Oracle very well. I did start making changes to the SubSonic source to get it to work for us, but then the corporate gods heard “Open Source” and decreed that SubSonic had to go. Nevermind that we had spent five months using it. I was given two weeks to come up with a new, homegrown, data layer. Well, two months later, we had our data layer. It reads the Oracle tables, views, functions, procs and packages and generates classes that can read/write/execute as appropriate. It turned out pretty well and is delightfully easy to use.

Next, up, the UI. The chosen toolset is Telerik RadControls for ASP.Net AJAX. (My previous experience is with Infragistics Windows toolset, so this was an interesting transition.) Users wanted the grid to be multi-edit. Teleriks grid does not support this natively, but it can be configured and coded to do it. But that is for another post.

Now, we are investigating MVC and Silverlight. I am hoping that my posts here will be of benefit to some as I explore these new technologies.


Tech Change – Again

May 6, 2008

Well, I have moved on.  After nearly eight years as the Lead Developer, and upgrading the App from Access 97 and VB 6 through SQL 2000, Access XP, VB.Net  to end up with SQL Server 2005 and C#, the company went after Java.  I completed my apprenticeship in the arcane arts of Maven, Ant and Cruise Control.  Getting our rather complex GWT build process fully automated was a challenge, but one I met.

Now, I am back in greener pastures.  However, nothing is ever easy.  After working on n-tier Windows based Enterprise Apps, I am now being introduced to the wonderful world of ASP and ASP.Net.  I am back with VB.Net.  The great news is that we are using VS2008 and .Net3.5.  I am still hoping for Silverlight, but I will not hold my breath.  I am happy with what I have to work with.  (Although, the back end is Oracle and that brings a whole new set of issues to the table.)

So, I have had my eyes opened to the wonderful world of Open Source.  (I can’t decide if my tongue is in my cheek on that “wonderful”  or not.)  So, of course, when I realized we had no ORM, my first thought was NHibernate.  I set up an example.  But the company is nervous about open source.  So, I tried Ideablade DevForce again.  Last time we looked at this product (a year ago), it was phenomenal.  I wish that every Developer Tool company would take a look at Ideablade’s Developer Concepts manual.  It is Excellent.

Anyway, it turns out the Ideablade is VERY n-tier app-centric.  There is some undocumented support for ASP but it is really an after thought.  So, I am back to NHibernate and it is working nicely.

The last tech change is from Infragistics to Telerik.  Apparently, Infragistics support for their web products was not very responsive, and because of that they lost a customer.  Now, we are using Telerik’s Ajax (Prometheus) Web Controls.  It took forever to figure out what properties to set to get the RadGrid to connect up to an ObjectDataSource that is in turn bound to an NHibernate data class.  In a future post I will explore this topic further and document the steps necessary.

Until then, I’m off to the hobby store.


Throwing my own Errors

January 3, 2008

So I created an error class today.  I needed to throw an exception if the scale to a rounding function was too large.   I created my own exception class:  InvalidScaleException.

In doing so, I stumbled across this article by Bill Venners back in ‘98.  It’s an excellent tutorial on Exceptions in Java.


Maven2 Log4J and JMX dependencies

December 31, 2007

Aarg!  What a nightmare.  I finally — fine, call me stupid — figured out where to/how to get the JMX dependencies for Log4J.
I am using Commons Logging, which in turn, likes to use Log4J.  So, I added this to my Maven project file (pom.xml):
<dependency>
  <groupId>log4j</groupId>
  <artifactId>log4j</artifactId>
  <version>1.2.15</version>
</dependency>

However, log4j has a dependency on jmx, which maven dutifully brings to my attention.

And this is where it gets interesting, the Maven repositories all have a pom for these but NOT the jar’s.
It turns out you need to download the jars from Sun’s Download site (which you have to register for).  (To navigate there, go to http://www.sun.com/download, then search the download center for JMX, then select the Java Management Extensions Download Information, then select the JMX 1.2.1 Reference Implementation,then select the JMX RI 1.2.1 download.  Whew!)

After downloading, you need to rename the jars from jmx*.jar to jmx*-1.2.1.jar.  Then you can register them with Maven (I use Artifactory, which made this a lot easier.)  Be sure to change the GroupId as follows:
com.sun.jdmk:jmxtools
com.sun.jmx:jmxri

With the jars in the repository, the JMX dependencies now resolve properly.


Fit Testing 101

December 29, 2007
Well, I finally got the Fitnesse server running and configured my first tests.  (Their site Fitnesse.org is down, but the Fitnesse jar’s were available here, and the zip was available on sourceforge.)  I run on Windows Vista, use Eclipse Europa as my IDE and Maven2 for the builds, so it was a bit of an ordeal to configure. Here’s what I ended up with.
My dev project is in standard Maven folders:
trunk>src>main>java>[package]>*.java
trunk>src>test>java>[package]>*Test.java
so I added:
trunk>src>test>fitnesse>[package]>fitnesse>fixtures>tests>FitTest*.java
(I’m quite sure that’s a naming violation of some sort, but it works for now. I can refactor it later when I find out what it should have been called.)

In my Eclipse project, I created this java class:
public class FitTestBasicTest extends ColumnFixture {
  public double quantity, price;
  public double extendedprice() {
    return quantity * price;
  }
}

I had to change the Maven pom to include the new test\fitnesse folder. So I used the build-helper-maven-plugin
<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>build-helper-maven-plugin</artifactId>
  <executions>
    <execution>
      <id>add-test-source</id>
      <phase>generate-sources</phase>
      <goals>
        <goal>add-test-source</goal>
      </goals>
      <configuration>
        <sources>
          <source>/src/test/fitnesse</source>
        </sources>
      </configuration>
    </execution>
  </executions>
</plugin>

Now, whenever I run mvn test, it will compile the Fit tests as well as the JUnit tests.

Meanwhile, I unzipped the Fitnesse server and edited the run.bat file so that Fitnesse uses port 8083 instead of 80 because I already have a TON of web servers running on my dev box.  I just changed the java line to include the port parameter, like this:
java -cp fitnesse.jar fitnesse.FitNesse -p 8083 %1 %2 %3 %4 %5

So, with the Fitnesse Wiki running, I connected to http://localhost:8083/.
Following the Fitnesse model in their Acceptance Tests, I created a MyTests.SuiteAcceptanceTests page. It took a lot of fiddling to figure out what the Classpaths should be and how to get Fitnesse to find the test Fixture itself, but this works:
!2 ''!-My-! Acceptance Tests Suites''
|^SuiteTests|''Test Various Acceptance Scenarios.''|
----
!2 ''Classpaths''
!path C:\workspace\trunk\target\test-classes\
!path C:\workspace\trunk\target\classes\
----
!2 ''Fixtures''
!fixture com.myapp.fitnesse.fixtures.firsttests.FitTestBasicTest

Naming the fixture in the Suite’s page allows the -Insert Fixture Table – combo at the bottom of the page editor to insert a table from the class definition in the test fixture.  I also created a MyTests.SuiteAcceptanceTests.SuiteTests.SetUp page to handle the namespace import:
!|Import|
|com.myapp.fitnesse.fixtures.firsttests|

Lastly, I created the MyTests.SuiteAcceptanceTests.SuiteTests. MyFirstTest page.
I selected the Insert Fixture Table combo and picked the FitTestBasicTest class. Fitnesse inserted the table so I added some values. It turned out I needed to delete the line from the table that shows the types.
!|FitTestBasicTest|
|quantity|price|extendedprice()|
|10 |20 |200 |

So, the code compiles, the unit tests run and pass, the fit tests run and pass. Now, to mavenize the whole process again and get the maven fitness plugin working so the tests are run automatically.


Setting up Eclipse for Testing

December 20, 2007

So I started trying to figure out how to do Unit testing in Eclipse.
Eclipse defaults to JUnit 3 tests, but I want to use JUnit 4 tests. But the Eclipse JUnit 4 plugin is version 4.3 and I want to use 4.4. Then there is the difference between Assert.True and Assert.That, the latter requiring (or at least benefiting from) Hamcrest.
So I finally removed the Eclipse Junit 4.3 library from my BuildPath and added the junit-4.4.jar and hamcrest-all-1.1.jar instead.
In the process, I came across this Unit Testing in Eclipse page, which includes the fit.jar. Well, that launched me into another search as I tried to figure out how to run Fit tests in Eclipse. It turns out that Chengyao Deng wrote his masters thesis on this topic. That led me to the FitClipse Installation Instructions.
Well, my testing configuration wouldn’t be complete without jMock, so I found the jmocklipse site. No code present, just a good idea in Google’s suite of good ideas. Oh well, I can include the external jar manually.
So, now I have Junit, Hamcrest, Fit and jMock all set up and ready to test.
Now…if only I had something to test…

Further Reading:
FIT and Eclipse
Using JUnit with Eclipse IDE


Back from the Spring Experience 2007

December 17, 2007

After spending 3 gorgeous days on the beach in Hollywood, FL (think Ft. Lauderdale), I have returned to a much cooler Charlotte than the one I left. No more record highs for us.

The Spring Experience 2007 was a great conference. As usual, some of the presenters demonstrated why nerds get a bad rep (can you spell b-o-r-i-n-g), others were excellent. In both cases, the content was great, its just the presentation style that lacks a certain je ne sais quoi. And that reminds me, where was the book store? Almost every single presenter has authored one or more tomes for our consumption, and yet here I sit on Monday morning with nary a one for my troubles. We did get a NFJS book as a consolation, but a book store in the lobby would have seriously helped my chiropractor’s Christmas budget. (As it was I had to unload 20 pounds of paper from my suitcase in order to not exceed the 50# per bag weight limit. Grrr.)

If Spring started its life as a Dependency Injection container, it has certainly come a long way. There are many new layers to this onion and it promises to keep growing. Rod Johnson, founder of Spring and now CEO of SpringSource (formerly Interface21), has brought many key players in the open source community together to create the formal infrastructure necessary to support Spring longer term.

I look forward to implementing the Spring Framework, Spring Security, Spring Web Services, Spring Web Flow, Spring Batch, Spring Integration, Spring Dynamic Modules, Spring, Spring, Spring, Spring, Spring, Spring Batch and Spring. :)