Wednesday 13 May 2009

MVC in a Java world

I've been having a play with the Java vevrsion of the Google App Engine. As I said the other day, it has been interesting coming back to Java after being in a C# land for such a long time.

Coming from C#, and particularly ASP.NET MVC, I've been looking for an equivalent in the Java world. It seems that Spring is a common choice, although there appears to be a lot to learn, and what I have learnt doesn't fit my mindset. That might be because I'm still getting to grips with the Java-WayTM. In particular coming from IIS and virtual directories to application servers and servlets.

So after not really finding what I was looking for, I thought I'd do something simple from scratch, so I grabbed hold of a template engine that I quite liked the look of, called FreeMarker. It was pretty straight forward to get my servlet to render using FreeMarker:


// Create the data for the view
Map root = new HashMap();
root.put("title", "FreeMarker Template Test - no JSP, oh yeah!");
// Grab the template
Template template = config.getTemplate("test.ftl");
// Write out the template
Writer out = response.getWriter();
template.process(root, out);

Note - The config object is an instance of freemarker.template.Configuration, which needs to be setup to enable the loading of your templates, this is pretty boring so I've ommitted it, you can find out about in the FreeMarker docs.

This bit of code is obviously useless without a template, so here it is:


<html>
  <head>
    <title>${title}</title>
  </head>
  <body>
    <h1>${title}</h1>
    <p>Hello, World!</p>
  </body>
</html>

This will produce the obvious, replacing ${title} with the string we specified in our servlet code, in this case "FreeMarker Template Test - no JSP, oh yeah!".

To deploy this I had to put the freemarker.jar in the WEB-INF/lib directory, and the test.ftl template was in a views subdirectory of the WAR.

Thursday 1 January 2009

Unpretty Monodevelop

When I build Monodevelop against the MacPort libraries it looks as follows:

As you can see you lose the 'nice' mac-like look and feel and it looks like the first version of Monodevelop that I built that, although this time I don't need X11. So because of this, I have recently taken to building against the libraries that come with the Mono Mac installer. By exporting the library path variables:

export DYLD_FALLBACK_LIBRARY_PATH=/Library/Frameworks/Mono.framework/Libraries:$HOME/lib:/usr/local/lib:/lib:/usr/lib:$DYLD_FALLBACK_LIBRARY_PATH

I found out about this from a comment by Arjan Timmerman on Bart's blog although this currently seems to be down.

Wednesday 19 November 2008

Success, sans X11

I've now managed to build MonoDevelop without the dependency on X11, and it looks so much prettier!

I followed the steps on NaizNoiz again, although I actually used the pre-packaged Mono installer as suggested in this comment rather than installing this with MacPorts.

I have noticed that the font used for the code has some slight alignment issues, it can be seen on the lines that read:

var eyes = Enumerable.Range()
.Select(i => i + i);

So I might try to find a fix for this at some stage. Although I think my priorities should be trying to get familiar with using MonoDevelop and it's underlying architecture. So to that end I've decided to take on a little project to produce a simple app. I'm going to try to make it run on both Windows and Mac, as I think that'll be an interesting and educational exercise. The backend will be SQLite probably with NHibernate, although I might try out SubSonic if that looks easier to get started with. For the frontend I'm not sure whether to use ASP.NET MVC or just do a desktop app.

I'll let you know how I get on...

Sunday 2 November 2008

Success... at last!

They have updated mono-addins in MacPorts, so I'm now trying to build MonoDevelop, with version 0.3.1 of mono-addins. The build was a success, so after disabling the Gettext Translation Support from the the graphical add-in setup utility, which is run using mdtool with the following command:

mdtool gsetup

Then I was able to disable the offending add-in and restart MonoDevelop.

Basically I followed the steps here and it all worked seamlessly!

Now that I have it up and running I've realised that it has to run from X11, so I'd really like to find out if this dependency can be got rid of and just get it running natively without an X-server. I don't really know anything about how these things work so that will be a lot of learning that I'll have to do.