• Post Reply Bookmark Topic Watch Topic
  • New Topic

Accessing Beans

 
Ravi Singh
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If a bean has a property accessor like:
public int getID();

, it can be accessed using the action:
<jsp:getProperty name="Bean" property="id"/>.

What happens if the bean accessor takes a parameter? e.g:
public int getID(int toGet);

How do you use the action property accessor to specify the parameter?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65531
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What happens if the bean accessor takes a parameter? e.g:
public int getID(int toGet);


If the method takes a parameter it is not, by definition, a bean accessor.


How do you use the action property accessor to specify the parameter?


You don't since in this case it is not a bean property.
 
Ravi Singh
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But you can have indexed properties such as:

int[] beanProperty;

To access this you need to specify an index.
 
Julian Kennedy
Ranch Hand
Posts: 823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could add a setter that sets the index as a private member and then a getter that accesses the array based on the current index. I realise that's a bit crap and not really what you're looking for, but it's a workaround if you find you need one.

Jules
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!