• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

EL - [ ] and .

 
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.
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
It means our mission is in jeapordy! Quick, read this tiny ad!
create, convert, edit or print DOC and DOCX in Java
https://products.aspose.com/words/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!