Win a copy of Terraform in Action this week in the Cloud forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Trying to invoke method using reflection

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello

I have a bean that looks like this



I need to dynamically call the getters of this bean from the jsp layer

So i am trying to create a new method in this bean, such as


The plan is to pass the name of the method (test) into the getColumnName method
Then invoke the method getTest and return the value

My problems are that i am new to java and dont really know what i am doing

Also, i do not know what to set paramValues to

In any other example of method.invoke that i have seen the object is the bean itself - how do i use my TransactionBean here?

Any help on this would be great thanks

Best regards

Patrick
 
Ranch Hand
Posts: 808
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Of course I don't know what you're trying to accomplish, but this seems like a really bad design. Surely there is a less violent way to achieve your goal. Please TellTheDetails and explain what your goal is. Apart from mentioning JSP, you haven't even said what tools you are using.
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your first problem is that you are declaring methods inside of your constructor. That's not allowed, so you need to fix that first.
Theh the first parametr to your invoke method needs to be an instance of the class that you are calling the method on. I think you can probably use this, but, like Dennis, I not exactly sure what you're trying to accomplish.
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just to add to the above: What you are trying to do may have already been done for you. Look up the EL language for JSP. This would let you access the getTest() method with something like {bean.test} instead of having to do <%bean.getColumnValue("Test");%>. EL will handle translating .test into .getTest() and doing the reflection for you.
 
Marshal
Posts: 74388
334
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That sounds too difficult for this forum. Moving discussion.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic