Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Managed-Bean question in JSF  RSS feed

 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • 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.
     
    Bill Dudney
    Author
    Ranch Hand
    Posts: 234
    • Mark post as helpful
    • send pies
    • 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
    Chrome IntelliJ IDE Mac OS X
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thanks Bill.
     
    Bill Dudney
    Author
    Ranch Hand
    Posts: 234
    • Mark post as helpful
    • send pies
    • 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
    Chrome IntelliJ IDE Mac OS X
    • Mark post as helpful
    • send pies
    • 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
    Chrome IntelliJ IDE Mac OS X
    • Mark post as helpful
    • send pies
    • 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??
     
    Consider Paul's rocket mass heater.
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!