File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Call JavaBean Method from JSP

 
John Storta Jr.
Greenhorn
Posts: 29
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is in some ways a hypothetical question, though I have run into some situations where I have needed to do this and I cannot find any documentation indicating it is possible.

I have a fairly basic JavaBean. I have no issues initializing it and getting/setting properties. What I cannot find any information on is how to call a plain old method in the bean from within a JSP page. By 'plain old method' I mean one that is not a getter or a setter.

Here is some sample code.




What I would like to do is something like this.



Where doSomethingCool() is a method defined in the bean.

I usually get around this by just creating a method called something like setDoSomethingCool(String ignoreMe), and then using setProperty to call the method.

Is it not possible to call a plain old method from within a JSP page?
If not, is there a reason?


Thanks
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64186
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
John Storta Jr. wrote:Is it not possible to call a plain old method from within a JSP page?

Nope. Doesn't follow the JavaBean specification.

If not, is there a reason?

See above.

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64186
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
P.S. You can call static methods by setting up an EL function, but not instance methods.
 
John Storta Jr.
Greenhorn
Posts: 29
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bear.

I think I have not been using beans properly then. I will have to look into whether or not what I am actually trying to do can be accomplished with static methods or perhaps change my code within the accessor methods.

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64186
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or, take a step back and check that what you are doing is appropriate for a JSP. Many times, if you find yourself having trouble doing something, it's because it should have already been handled by the controller.

 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic