Alex Rivera | Logout

getting boolean properties from objects in jsp el

Asked 2009-02-05T22:51:54.097
9

I have an instance of the following object in the jsp page context:

Class User{
  private boolean isAdmin;
  public boolean isAdmin(){return isAdmin}
}

How can I query the isAdmin property from the EL? This doesn't seem to work:

${user.admin}

nor does this:

${user.isAdmin}

thanks!

-Morgan

Edit
Report

1 Answer

0

Try this:

${user.Admin}

just in case capitalization is the problem. Sometimes EL does non-obvious things. However, I've usually been able to just use the equivalent of ${user.admin} in my el. Looking at my own code, I have many examples of doing the obvious thing where it works.

Do you have the following methods in your class:

  public boolean isAdmin(){return isAdmin}

  public void isAdmin(boolean newValue) { ... }

or do you have only the getter? If my code, I notice that I do not do the above. My setters all start with set such as:

  public boolean isAdmin(){return isAdmin}

  public void setAdmin(boolean newValue) { ... }

and I am able to use the obvious lowercase solution ${user.admin} in my JSPs. This may depend on which EL processor you're using.

NOTE: Added later because people still vote this down, obviously never having run into an example where this occurs. An example from my own JSPs that caused me to ask this question is that I have a method:

public int getLANSomething() { ... }

and I access this in EL as follows: ${agent.LANSomething} The rule appears to be getXXXyyy where XXX is all caps, you have to use caps to access it in EL. At least with Tomcat versions 4-6 that I have used.

answered 2009-02-05T23:10:06.433

Your Answer