• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Use of Class constants in EL expressions

 
Akshay Singhvi
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Ranchers,
Can we use constants declared in a class file in EL expressions for eg.
public class A {
public static final String a = "AB";
}

Now in the JSP, assume i have imported the class A then will this work
${A.a == "AB"}
 
rohini gundu
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes you can use that expression in your jsp. The statement will return either true or false.
 
Niranjan Deshpande
Ranch Hand
Posts: 1277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why is it that, EL works with static members only ?
static methods, static fields ???

 
Sayak Banerjee
Ranch Hand
Posts: 292
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It won't produce any errors but it would never work the way you want it to.....remember when you say {A.a} then A is treated as an attribute in any of the scopes,which being absent in this case {A.a} returns nothing and {A.a=="AB"} obviously returns false.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic