How to deal with property other than String and primitives?

Suppose in the above example the Emp class has a Dog(class) property. The Dog property has also the getter and setter methods same as others. Which is a separate class and that(dog) has also attributes name and color.
Class Emp{
Private String name;
Private int empno;
Private String city;
Private Dog dog;
}
Class Dog{
Private String name;
Private String color;
}

We can not get the Dog property like this
<jsp:getProperty name=”employee” property=”Dog”/>
We will get some output like this, foo.Dog@867686687
There is no way in standard action to get the dog name. The <jsp:getProperty> lets you access only the properties of the bean attribute(String or primitives or Wrapper). There is no capability for nested property where you want a property of a property, rather than property on an attribute.
So how to display the property of dog(suppose dog name)?
Using scripting:
<%=(foo.person)request.getAttribute(“person”).getDog().getName()%>
Using expression language:
${person.dog.name}

No comments:

Post a Comment