Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Use a UseBean id within a scriptlet  RSS feed

 
Vijay Bala
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have defined a bean using useBean and want to use it within a scriptlet to get a string value from a getter method. It gives me an error saying method getSilo() not found in test1.UserFormBean. I have defined the class UserFormBean as public and the method getSilo() as public. Here is my bean definition :

package test1;
import com.client.JspBean;
public class UserFormBean extends JspBean {...
String silo = null;
public UserFormBean() {
super();
setJspDataName("UserFormBean");
}
public String getSilo()
{
return silo;
}
I have used the foll. code in my jsp page :
<%@ page import="test1.*"%>
<jsp:useBean id="UserFormBean" class="test1.UserFormBean" scope="request">
</jsp:useBean>
<%
String silo = null;
String objSilo1 = UserFormBean.getSilo(); <======//error obtained here
if (objSilo1 == null) {
silo = "personal";
}
%>
I keep getting the error : Method getSilo() not found in class test1.UserFormBean. How can i use
UserFormBean.getSilo()
to store it in a string since i need to manipulate in diff. ways in my code and need to store the value in a string instead of using <jsp:getProperty..
I even tried using the code directly and not using useBean with request scope.

test1.UserFormBean UserFormBean = (test1.UserFormBean)request.getAttribute("UserFormBean");
if (UserFormBean == null) {
UserFormBean = new test1.UserFormBean();
request.setAttribute("UserFormBean", UserFormBean);
}
Thanx in advance,
Vijay
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're trying to call an instance method as though it was a class method! You need to give a name to your bean (with the beanName= attribute) so the code can reference that particular instance of UserFormBean:

[ January 24, 2002: Message edited by: Tim Holloway ]
 
Manohar Karamballi
Ranch Hand
Posts: 227
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try by giving different id to bean that is not same as class name..
Rgds
Manohar
 
lakshman Srilakshmanan
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
Tim Holloway example gives me the following error :
jsp:useBean tags cannot specify both class and beanName probably occurred due to an error
Any help.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!