Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using Beans with non-null constructors

 
Richard John
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's a simple question, I daresay the answer is going to be a simple you can't do that, but a word from an "expert" would settle my mind!
I've been using beans in my JSP files like so:
<jsp:useBean id="loginBean" scope="page" class="com.rttp.CheckLogin">
These beans have empty constructors, all nice and easy.
Now suppose I want a java class that that has a constructor, say:
public ObjectManager (String msg)
{
System.out.println(msg);
}
How do I use this class as a Bean using the useBean tags? Or is this now not a bean?

Thanks for your help.
Rich
 
Jason Menard
Sheriff
Posts: 6450
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In order for a class to be a bean, one of the requirements is that it has a no argument contructor. Your example doesn't have a no argument constructor, so it's not a bean.
Jay
 
Richard John
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I should have known you were going to say that!
Anyway thanks... I just needed to hear it from someone else :-)
 
Richard John
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I should have known you were going to say that!
Anyway thanks... I just needed to hear it from someone else :-)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic