• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt on EL Please Help...

 
Vepa Sritej
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Consider the following class
**********************class**************************
public class ServentMaid extends Profession{

private String maidName;
private int salary;
private ArrayList houses;
private HashMap owners;

public String getMaidName() {
return maidName;
}


public void setMaidName(String maidName) {
this.maidName = maidName;
}

}
public ArrayList getHouses() {
return houses;
}
public void setHouses(ArrayList houses) {
this.houses = houses;
}
}
********************class**********************************

I have set one request attribute like this...

Consider sm as an object of ServentMaid class

request.setAttribute("maid",sm);

Now in a JSP ive used the following two EL expressions..

${maid[houses['one']]}
${maid.houses['one']}

I was in an impression that both of them must result in an exception stating :

The "[]" operator was supplied with an index value of type "java.lang.String" to be applied to a List or array, but that value cannot be converted to an integer.

But to my suprised the first one did not give an exception while the latter one gave. Can anyone help me why this is.Whats the difference in the evaluation between the two expressions.

Thanks in advance.

[ October 15, 2007: Message edited by: Vepa Sritej ]
[ October 15, 2007: Message edited by: Vepa Sritej ]
 
Michael Ku
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did the first one work or just not throw an exception?
 
Vepa Sritej
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The first one did not give the output but it did not throw an exception as well...
 
Michael Ku
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you look into the spec as to how it processes the [] operator it may give you a clue as to what is happenning
 
Vepa Sritej
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think in the first case it treates the expression inside the braces as a key to a Map . Since it fails to find such key-value pair , it prints nothing , instead of throwing an exception.

The latter case is evident though...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic