New Framework for Custom Rendering of Types

Jul 17, 2013 at 4:12 PM
I've started work on a framework to complement NakedObjects MVC and I'm wondering if it's of use to other NO fans. The basic idea is this: I replace the call to PropertyList and PropertyListEdit in my shared views with a custom method that provides much the same output, with the caveat that custom rendering methods can be defined based on the type of a property. I call it FigLeaf.

For example, my current project involves a number of addresses and lat/lon coordinates; my classes for thes ComplexTypes are Address and Coordinates, respectively. So, I reference FigLeaf in my MVC project and mark up the assembly and my HTMLHelper extensions class with the FigLeafRenderer attribute. Then, I create an extension method called RenderCoordinatesProperty and one called RenderAddressProperty. Now, whenever there's a set of coordinates or an address in my database, my custom rendering method adds a Google Maps IFrame; this is very handy to my users, who often need information that Google maps can give them, e.g. local businesses in the area.

In short, the goal is to be able to present my data in a more meaningful way than breaking it down to its scalar values, while still relying on NO to do the heavy lifting.

Is this something that others here may find useful?
Jul 17, 2013 at 6:24 PM
Nice. Yes, I think that sounds useful.
I'd like to hear what Richard and Stef think. Is this a good approach for this kind of extension?
Jul 17, 2013 at 7:21 PM
Agreed, useful. Nice to see.

The next step would be to support custom rendering of either single entity objects and of collections of entities.

In Isis we have a bit of API for this, allowing pluggable components: eg gmap3 [1] (renders any entity or collection which implements Locatable); eg wickedcharts [2] (renders either a scalar value chart or a collection of objects that have numeric properties), eg excel [3] (renders any collection as a link to download as an Excel spreadsheet)

If providing alternative representations, there also needs to be a mechanism to allow the user might want to switch between any of these different representations. In Isis, we provide a button to switch between then ([4], red box top right).

I'm not sure if this needs to be part of NO MVC or not; following algernon83's lead, one could imagine custom "widget sets" that offer similar capabilities. The question is where is the NO MVC API? Right now these HTML helpers (and presumably algernon83's) make calls down into the NOF metamodel, which isn't formal API (so far as I am aware). The NOF.Surface DLL is one obvious candidate for such an API, I suppose?


Jul 17, 2013 at 8:15 PM
Hi dkhaywood --
Looks like we're moving in similar directions. I like your concept of switching between different supported views. My current implementation looks for the first available method titled "Render{ClassName}Property"; I could change it to look for any method with a "FigLeafRendererFor(typeof(T))" attribute.
FigLeaf makes minimal calls to the public, undocumented helper methods of NO MVC, e.g. NakedObjects.Web.Mvc.Html.PropertyExtensions.Contents to get the title of an object and NakedObjects.Web.Mvc.Html.PropertyExtensions.Name to get the display name of a property. It would be great if such helper methods in NO MVC were documented, but, even if they were made private, they're small enough to be re-implemented directly in FigLeaf. The basic functions of rendering an object as set of properties and a collection as a list or a table are already re-implemented.
Custom rendering methods for collections is already implemented in FigLeaf; it just looks for a "RenderCollectionOf{ClassName}Property" method. Again, your Isis example demonstrate where it would be good to have multiple rendering methods exposed.
Jul 22, 2013 at 8:58 AM
This looks interesting. If you already have plans for making it available, please let us know where.

If not, your posting has prompted me to get on with something that's been on my TODO list for a while ... I have just set up a NakedObjects.Contrib repository on GitHub ( ). If you would like to post anything you've done there, just let me know your GitHub user name.

(The same goes for anyone else on this forum who would like to make any code they've written that extends/modifies/applies Naked Objects).