tags:

views:

68

answers:

2
Class Foo
{
   public String currentVersion()
   {
     return "1.2";
   }
}

need to call currentVersion class method from jsp using tag library? where currentversion is not getter or setter method ,it is just a class method.

+2  A: 

You can't do this with standard JSP expressions like ${foo.currentVersion}, that only works with bean proprties (i.e. getCurrentVersion()).

You need to either

  • Write a scriptlet (don't do it!)
  • Write a custom tag class that calls currentVersion() for you
  • Refactor Foo to have a getCurrentVersion() method
skaffman
how shall i write custom tag in order to call that method ?
kedar kamthe
http://java.sun.com/javaee/5/docs/tutorial/doc/bnalj.html
skaffman
Blah, I had a feeling that was the answer when I saw this. I *really* didn't want to have to write my own custom tag class.
R. Bemrose
A: 

Simply rename you method to getCurrentVersion(), there is nothing in the JavaBeans specification that says that a "getter" method has to return the value of an attribute on the class. A getter method can simply return a constant value like you have.

class Foo {
    public String getCurrentVersion() {
        return "1.2";
   }
}
Tendayi Mawushe