This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

problem encountered while using jsp:getProperty tag  RSS feed

 
Rhea Karnam
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I encounter an exception while using jsp tags, as in the given snippet of code:
<jsp:useBean id="abc" class="com.package1.Class1" scope="request">
<%
if(abc!= null)
{
%>
<jsp:getProperty name="abc" property="attribute1"/>
<%
}
%>
Error encountered:
getProperty(abc): cant find method to read {1}
-----------------------------------------------
Please note that the bean exists, with the correct attribute name and accessor.
What I understood: When the bean of the given id and class is not found in the
scope, a new instance gets created. (I can see the bean's cosntructor getting called.)
My doubts:
1. is this by design?
2. My need is to diplay the property's name, only if the bean exists in the scope. What's the ideal way to achieve this, using tags? I can achieve the same result by using jsp scripts in place of the getProperty tag. But, I would like to know why my other approach gives me an exception.
 
Kaustubh Patil
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

What I understood: When the bean of the given id
and class is not found in the scope, a new instance gets created. (I can see the bean's cosntructor getting called.)
My doubts:
1. is this by design?

Yes this is by design. Whenever you create a bean and it is not found in the scope specified a new instance of it is created for that scope.
The getter method for the "attribute1" should be

Also the bean should have a "attribute1" as one of its class variable.
Could you please paste the code of your bean. It will be helpful to understand why this error is happining.
-Kaustubh
 
Rhea Karnam
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Kaustubh,
Thanks for the reply.
Your reply solved my problem.
The getter method that I had coded, is actually performing a few additional processing on the attribute's value, and its return type is not the same as the attribute's type. I think that is why I was getting the exception.
Furthur to it, I have a few more doubts (just being inquisitive):
1) can the attribute, on which I use the getProperty tag, be protected? Is there any condition related to the access-level of the attribute?
2) Also, should the getter that I define for the attribute be a simple-getter?
I mean assuming that I have an attribute named attrib of type int,
and its accessor as given below:
public int getAttrib()
{
//modify attrib's value before returning it
}
In this case, can I use
<jsp:getProperty name="idname" property="attrib" />
to invoke this method ?
Thanks a heap.
Rhea
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!