You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by den frei <db...@centralpets.com> on 2006/04/25 10:51:52 UTC

accessing collection properties in javabeans

in my sqlmapping, the parameterClass attribute in my statement element is a javabean which has a java.util.List as a property.  Here is an example:

public class SearchReq
{
private java.util.List cities;//list of City objects
//..getters & setters
}

public class City
{
private String id;
private String name;
//..getters & setters
}

ibatis doesn't seem to like #cities[0].id#, it bombs when i start tomcat.  It looks ok by the documentation, so how do i get it to work?  Here is the section of the doc:

Object Graph Navigation (JavaBeans Properties, Maps, Lists)

Throughout this document you may have seen objects accessed through a special syntax that might be familiar to anyone who has used Struts or any other JavaBeans compatible framework. The iBATIS Data Mapper framework allows object graphs to be navigated via JavaBeans properties, Maps (key/value) and Lists. Consider the following navigation (includes a List, a Map and a JavaBean):

Employee emp = getSomeEmployeeFromSomewhere();
((Address) ( (Map)emp.getDepartmentList().get(3) ).get (“address”)).getCity();

This property of the employee object could be navigated in an SqlMapClient property (ResultMap, ParameterMap etc…) as follows (given the employee object as above): “departmentList[3].address.city”

---------------------------------------------
This e-mail was sent using a CentralPets.com WebMail account
Get yours at: http://mail.centralpets.com