Tuesday, June 28, 2005

MonoRail & WebControls

So there's a small problem with MonoRail. No WebControls. No really, it is relatively speaking not much of a problem. Since it mostly doesn't use PostBacks, there's not much point in ViewState, so a TextBox is just a input. So why not just write the markup for the input in the View?

The problem comes in when you start talking about rendering "Grids", charts, etc. More complex controls.

So what do you do? Well, one way is to basically go back to an ASP Classic style for Views. Not real pretty though. Another way is to write Helpers. You can only have so many overloads for a method though in a practical sense though or it starts to look ugly. So what then? You can pass a single path or name that tells the Helper where to go to look up the specifics on how to render a control. Then you could end up with lots of extra little "Viewlets" though.

Or we can take a cue from ASP.NET and implement our own tags. The namespace alias could refer to a helper, and the element name could refer to a specific control... or perhaps we could use "rails" as the namespace alias, and the element name would then refer to the Helper. That seems a bit cleaner. So you'd end up with something like this:

public class GridHelper: AbstractHelper, IControlHelper {
public string Render(XmlElement node) {
IList results = this.Controller.PropertyBag[node.Attributes["results"]] as IList;

// do stuff with the "rails" element passed in, and the matching
// data pulled from the Context.

Then you'd use it like this:

<rails:Grid id="blah" style="borders: none;" results="results">
<column name="Meh" />
<column name="Moo" />

I think that'd be cool... I have no idea what changes this would require in MonoRail or NVelocity right now though. I'll try to find the time to do so.
Comments: Post a Comment

<< Home

This page is powered by Blogger. Isn't yours?