Hmmm, I didn't think about OGNL, that might be an interesting thing to
investigate. At this point, I just wrote my own version of BeanMap that
does support dot notation, and it seems to be working so far. Thanks for
your help.
(*Chris*)
On Nov 12, 2011 12:49 AM, "Maurizio Cucchiara" <[email protected]>
wrote:
> Hi Chris,
> I don't know if BUM allows what you are trying to achieve.
> Would you consider to use OGNL instead?
>
> @Test
> public void testOGNL() throws Exception {
> OgnlRuntime.setNullHandler(Student.class, new StudentNullHandler());
> Student student = new Student();
> Map<String, Object> context = Ognl.createDefaultContext(student);
> Ognl.setValue("id", student, 1);
> Ognl.setValue("course.name", student, "course name");
> assertEquals(1, student.getId());
> assertEquals("course name",student.getCourse().getName());
> }
>
> private static class StudentNullHandler implements NullHandler {
> public Object nullMethodResult(Map<String, Object> context,
> Object target, String methodName, Object[] args) {
> return null;
> }
>
> public Object nullPropertyValue(Map<String, Object> context,
> Object target, Object property) {
> final Course course = new Course();
> ((Student)target).setCourse(course);
> return course;
> }
> }
>
>
> Twitter :http://www.twitter.com/m_cucchiara
> G+ :https://plus.google.com/107903711540963855921
> Linkedin :http://www.linkedin.com/in/mauriziocucchiara
>
> Maurizio Cucchiara
>
>
>
> On 11 November 2011 19:43, Chris Pratt <[email protected]> wrote:
> > I simplified my test case and I think I may have found the culprit. I
> was
> > expecting the BeanMap to handle dot notation properly, but it appears I
> was
> > mistaken. The following doesn't seem to work:
> >
> > public static void main (String... args) throws ADKException,
> IOException {
> > Student student = new Student();
> > Map studmap = new BeanMap(student);
> > studmap.put("id",4242);
> > studmap.put("name.firstname","Chris");
> > studmap.put("name.lastname","Pratt");
> > student.dump();
> > } //main
> >
> >
> > I get an IllegalArgumentException that Student has no property called
> > name.firstname. Is there any way around this? BeanMap isn't really
> useful
> > to me if it doesn't support the object hierarchy that a bean engenders?
> > (*Chris*)
> >
> > On Thu, Nov 10, 2011 at 5:06 PM, Maurizio Cucchiara
> > <[email protected]>wrote:
> >
> >> I'm not sure this is what you are looking for, I'm assuming you are
> >> trying to write into the student bean, I hope this will be useful (it
> >> works on my side):
> >>
> >> @Test
> >> public void testBeanMap() throws Exception {
> >> Student student = new Student();
> >> BeanMap map = new BeanMap(student);
> >> assertNotNull(map);
> >> map.put("id", 1);
> >> map.put("course", new Course("course name"));
> >> assertEquals(1, student.getId());
> >> assertEquals("course name",student.getCourse().getName());
> >> }
> >>
> >>
> >> Twitter :http://www.twitter.com/m_cucchiara
> >> G+ :https://plus.google.com/107903711540963855921
> >> Linkedin :http://www.linkedin.com/in/mauriziocucchiara
> >>
> >> Maurizio Cucchiara
> >>
> >>
> >>
> >> On 11 November 2011 01:51, Chris Pratt <[email protected]> wrote:
> >> > StringMapAdaptor
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: [email protected]
> >> For additional commands, e-mail: [email protected]
> >>
> >>
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>