Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

EL - [ ] and .

 
saps rao
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

As per the HFSJ book, the [ ] operator can be used anywhere in the place of the . operator.
In the code magnets exercise in page 379-380 (in HFSJ), the person's dog's toy's name is accessed using ${person.dog.toys[0].name}.

Below are the classes (relavant part).

public class Person
{
private Dog dog;
public void setDog(Dog dog){
this.dog = dog;
}
public Dog getDog(){
return dog;
}
}

public class Dog
{
private Toy[] toys;
public void setToys(String[] toys){
this.toys = toys;
}
public Toy[] getToys{
return toys;
}
}

public class Toy{
private String name;
public void setName(String name){
this.name = name;
}
public String getName(){
return name;
}
}

And a an attribute named "person" is set using a servlet and forwarded to a jsp.

If I want to access the dog's toy's name using only [ ] operator, how can I do that?

thanks,
swapna.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic