• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:outputText 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 ]
 
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:outputText 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...
 
Pat Peg
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?

 
reply
    Bookmark Topic Watch Topic
  • New Topic