Tim Scott's Blog

September 11, 2007

Monorail: CheckboxListComponent

Filed under: C#, Castle Project, Monorail — Tim Scott @ 1:10 pm

I have recently created CheckboxListComponent and added it to CastleContrib ViewComponents. This Monorail view component provides a simple way to render data-bindable checkbox lists. Check it out. I hope you like it and find it useful!

July 21, 2007

Monorail: ColumnChartComponent

Filed under: C#, Castle Project, Monorail — Tim Scott @ 7:04 pm

Many Webforms developers are resistant to Monorail and for various reasons. I would guess that the second biggest reason, behind simple intertia, is the perceived lack of rich UI components. Recently Ayende decided to do something about it by adding a Castle.MonoRail.ViewComponents to Castle Contrib. It’s a place to aggregate view components that might be generally useful to Monorail UI development.

I have recently created ColumnChartComponent and added it to CastleContrib. ColumnChartComponent renders fairly basic column charts. (By “column chart” I mean charts with vertical bars.) Check it out.  I hope you like it and find it useful!

June 14, 2007

Ordering Computed Fields In ActiveRecord With ICriteria

Filed under: Active Record, C#, Castle Project — Tim Scott @ 11:48 pm

If you use ActiveRecord and ICriteria to fetch collections, this probably looks familiar:

DetachedCriteria criteria = DetachedCriteria.For(typeof(TaskEstimate));
IList<TaskEstimate> estimates = TaskEstimate.FindAll(criteria);

The criteria object tells the FindAll method to sort the results ascending by the persisted property, “OptimisticHours.” But let’s say you have another persisted property “PessimisticHours,” and you want to sort by the difference between the optimistic and pessimistic estimates. That is to say, you want to sort by a computed value instead of a persisted property. Here’s how:

First you add the following to the TaskEstimate class:

private int _estimateDelta;
[Property(Formula = "PessimisticHours - OptimisticHours")]
public int EstimateDelta
    get { return _estimateDelta; }
    set { _estimateDelta= value; }

Then you can do this:

IList<TaskEstimate> estimates = TaskEstimate.FindAll(criteria);

What’s happening here is that ActiveRecord is providing us access to the NHibernate mapping feature that allows you to define a property with a formula attribute.

Blog at WordPress.com.