Win a copy of Head First Android this week in the Android 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

Use a UseBean id within a scriptlet

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Saloon Keeper
Posts: 24551
168
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 227
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try by giving different id to bean that is not same as class name..
Rgds
Manohar
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
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