File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSF and the fly likes Constructor bean problems?-is it being over-written? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Constructor bean problems?-is it being over-written?" Watch "Constructor bean problems?-is it being over-written?" New topic

Constructor bean problems?-is it being over-written?

Pat Peg
Ranch Hand

Joined: Feb 04, 2005
Posts: 195
I don�t think my constructor is being called. Here is the code and the output.

<managed-bean-name>UserBean</ managed-bean-name>
<managed-bean-class>com.bean.UserBean</ managed-bean-class>
<managed-bean-scope>session</ managed-bean-scope>
<description>Test String</description>
<property-class>java.lang.String</ property-class>

public final class UserBean extends Object{
public UserBean(){
this.setTest(�I�m the constructor string�);
public void setTest(String test){
this.test = test;
public String getTest(){
return test;
//return �I�m from the method�;
private String test;

In the jsp�.

Test String here -> <hutputText value=�UserBean.test�/> <-Test String there

If I just return test as it is written I get null basically or output like this�
Test String here -> <-Test String there

If I return the �I�m from the method� string obviously I get�.
Test String here -> I�m from the method <-Test String there

I have also tried adding a string to the value tags in the config file-still null and that wouldn�t have helped anyway. So what is going on? I thought you could have a constructor actually, well, construct in JSF but this one looks like it is being over-written or something.

correction-the constructor must be called because I put a database connection manager in this constructor and then used it to get a connection and verify a user name that was also passed in....that part worked.
[ June 01, 2007: Message edited by: Pat Peg ]
Josh Juneau
Ranch Hand

Joined: Jun 16, 2004
Posts: 86
Did you paste your code correctly? When obtaining a value from the bean, you must use the JSF EL syntax:

Test String here -> <hutputText value=�#{UserBean.test}�/> <-Test String there

If you are not using the #{} around your value, it is not binding to the bean.

Hope this helps...

Database Administrator/Application Developer
Pat Peg
Ranch Hand

Joined: Feb 04, 2005
Posts: 195
Good catch but that wasn't it-that was a typo when I was writing up the problem.

I am looking at work arounds but I would still like to know why?

I agree. Here's the link:
subject: Constructor bean problems?-is it being over-written?
It's not a secret anymore!