| Author |
Constructor bean problems?-is it being over-written?
|
Pat Peg
Ranch Hand
Joined: Feb 04, 2005
Posts: 188
|
|
I don�t think my constructor is being called. Here is the code and the output. Faces-config <managed-bean> <managed-bean-name>UserBean</ managed-bean-name> <managed-bean-class>com.bean.UserBean</ managed-bean-class> <managed-bean-scope>session</ managed-bean-scope> <managed-property> <description>Test String</description> <property-name>strTest</property-name> <property-class>java.lang.String</ property-class> <value></value> </managed-property> </managed-bean> 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�. <f:view> Test String here -> <h utputText value=�UserBean.test�/> <-Test String there </f:view> 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: <f:view> Test String here -> <h utputText value=�#{UserBean.test}�/> <-Test String there </f:view> 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: 188
|
|
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?
|
 |
 |
|
|
subject: Constructor bean problems?-is it being over-written?
|
|
|