• 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

Managed-Bean question in JSF

 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When I create a JavaBean and then create a Managed-Bean entry for this JavaBean in my faces-config.xml file, it might look something like...

What I don't understand is why I have to create a JavaBean and define the managed-property elements. It would seem that JSF should:
  • Find all the properties in the JavaBean via some form of inspection OR
  • Dynamically create the JavaBean with the <managed-properties> element eleminating the need for me to hand code the Bean.


  • Any info regarding this would be appreciated.
     
    Author
    Posts: 234
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Greg,
    I get your point... Much of what you put in the managed beans tags is derivable via reflection. I guess the spec developers wanted you to tell them so they would not have to reflect...
    My best guess but I don't know for sure, good question for the expert group though.
     
    Gregg Bolinger
    Ranch Hand
    Posts: 15304
    6
    Mac OS X IntelliJ IDE Chrome
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Thanks Bill.
     
    Bill Dudney
    Author
    Posts: 234
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Greg,
    I think I misread your question.
    On second read (after I posted of course ) I realized what I'd posted was wrong...
    JSF will reflect. All you have to do is specify the class name, JSF will create it and look for get/set methods based on the EL expression.
    For Example:
    here is part of my faces-config.xml file
    <managed-bean>
    <description>
    Manages the registration stuff
    </description>
    <managed-bean-name> regPage </managed-bean-name>
    <managed-bean-class> register.model.RegistrationPage </managed-bean-class>
    <managed-bean-scope> session </managed-bean-scope>
    </managed-bean>
    Here is a part of the JSP that uses it...
    <h:inputText value="#{regPage.user.firstName}">
    <f:validateLength maximum="20" minimum="0"/>
    </h:inputText>
    I did not have to specify that 'user' was a property. The only time you have to do that is if you want to specify a default value.
    Hope this helps.
     
    Gregg Bolinger
    Ranch Hand
    Posts: 15304
    6
    Mac OS X IntelliJ IDE Chrome
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Thanks again Bill. I'll change my code and make sure I haven't done something wrong. It seems like I tried that and it didn't work. But I will try again right now....
     
    Gregg Bolinger
    Ranch Hand
    Posts: 15304
    6
    Mac OS X IntelliJ IDE Chrome
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Ok, it worked just fine. I must have been doing something wrong earlier. It would be nice, however, if I was able to add the managed-properties and rid myself of a hard coded JavaBean. Maybe a feature request for the next release??
     
    Don't get me started about those stupid light bulbs.
    reply
      Bookmark Topic Watch Topic
    • New Topic