I have found why this behaviour exists but am not sure whether this is by design or is a bug. When DefaultConverter tries to convert a Nullable type, it doesn't treat 'null' as a valid value and so simply returns 'null'. However a generic list requires the NULL to be cast to teh Nullable type . The fix is simple, simple have ACtivator create an instance of the nullable type passing NULL as the value.
But I am not sure whether this patch would be accepted or not. To me it seems logical that a nullable list would have null values, but I could see the other side too. Now if we are just talking about a List<double> then it seems like it should add as many items as it can ... in the example below add 2 items. However right now it simply doesn't add any items because of the exception thrown on the list...again, I am not sure whether to roll my own or submit a patch. Any monorail devs have a take on this? On Jan 29, 12:19 am, Mike Nichols <[email protected]> wrote: > I hate to post about databinder stuff, but this seems odd. > What is the expected behaviour binding to a params dictionary like: > params["obj.SomeList[0]"]="123" > params["obj.SomeList[1]"]="456" > params["obj.SomeList[2]"]="" > params["obj.SomeList[3]"]="" > > I swear DataBinder used to add 2 items to obj.SomeList (List<double?>) > but I just moved to IIS7/server 2008 and now it doesn't add any values > at all. However if 'null' is the value instead of empty strings then > it works just fine. > > I am using today's trunk. > > Here are tests demonstrating... > The first test here PASSES, but the other two FAIL...note that NULL > values allow DataBinder to create and hydrate the list as expected. > Has anyone else come against this?: > > public class when_binding_indexed_properties_with_null_list_itemas : > context_spec > { > private ControllerBindingLIst sut; > private StubMonoRailServices services; > private IControllerContext controllerContext; > private StubEngineContext engineContext; > > public override void establish_context() > { > services = new StubMonoRailServices(); > sut = new ControllerBindingLIst(); > controllerContext = services.ControllerContextFactory > .Create("", "home", "MyAction", > services.ControllerDescriptorProvider.BuildDescriptor(sut)); > > engineContext = new StubEngineContext(); > engineContext.Request.Params.Add("entity.List[0]", "123"); > engineContext.Request.Params.Add("entity.List[1]", "456"); > engineContext.Request.Params.Add("entity.List[2]", null); // > databinder recognizes this > engineContext.Request.Params.Add("entity.List[3]", null);// > databinder recognizes this > > } > > public override void because() > { > //given > sut.Process(engineContext, controllerContext); > } > [Observation] > public void should_not_be_null() > { > Assert.NotNull(sut.list); > } > [Observation] > public void should_have_two_list_items() > { > Assert.Equal(2, sut.list.Count); //passes > } > > } > > public class when_binding_indexed_properties_with_empty_list_items : > context_spec > { > private ControllerBindingLIst sut; > private StubMonoRailServices services; > private IControllerContext controllerContext; > private StubEngineContext engineContext; > > public override void establish_context() > { > services = new StubMonoRailServices(); > sut = new ControllerBindingLIst(); > controllerContext = services.ControllerContextFactory > .Create("", "home", "MyAction", > services.ControllerDescriptorProvider.BuildDescriptor(sut)); > > engineContext = new StubEngineContext(); > engineContext.Request.Params.Add("entity.List[0]", "123"); > engineContext.Request.Params.Add("entity.List[1]", "456"); > engineContext.Request.Params.Add("entity.List[2]", > "");//databinder > consequently disregards all values > engineContext.Request.Params.Add("entity.List[3]", ""); > > } > > public override void because() > { > //given > sut.Process(engineContext,controllerContext); > > } > [Observation] > public void should_not_be_null() > { > Assert.NotNull(sut.list); > } > [Observation] > public void should_have_two_list_items() > { > Assert.Equal(2,sut.list.Count); //FAILS, saying zero items > are in > the list > } > > } > > public class when_binding_repeated_properties_on_sdc : context_spec > { > private ControllerBindingLIst sut; > private StubMonoRailServices services; > private IControllerContext controllerContext; > private StubEngineContext engineContext; > > public override void establish_context() > { > services = new StubMonoRailServices(); > sut = new ControllerBindingLIst(); > controllerContext = services.ControllerContextFactory > .Create("", "home", "MyAction", > services.ControllerDescriptorProvider.BuildDescriptor(sut)); > > engineContext = new StubEngineContext(); > engineContext.Request.Params.Add("entity.List", "123"); > engineContext.Request.Params.Add("entity.List", "456"); > engineContext.Request.Params.Add("entity.List", ""); > engineContext.Request.Params.Add("entity.List", ""); > > } > > public override void because() > { > //given > sut.Process(engineContext, controllerContext); > > } > [Observation] > public void should_not_be_null() > { > Assert.NotNull(sut.list); > } > [Observation] > public void should_have_two_list_items() > { > Assert.Equal(2, sut.list.Count); //same thing...fails saying > zero > items are in list > } > > } > > //ENTITIES USED > public class ObjWithList > { > List<double?> list=new List<double?>(); > > public List<double?> List > { > get { return list; } > set { list = value; } > } > > } > > public class ControllerBindingLIst:SmartDispatcherController > { > public List<double?> list; > > public void MyAction([DataBind("entity")] ObjWithList entity) > { > this.list = entity.List; > } > > } --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Castle Project Users" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/castle-project-users?hl=en -~----------~----~----~----~------~----~------~--~---
