aspose file tools
The moose likes JSP and the fly likes Managed-Bean question in JSF Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » JSP
Reply Bookmark "Managed-Bean question in JSF" Watch "Managed-Bean question in JSF" New topic
Author

Managed-Bean question in JSF

Gregg Bolinger
Ranch Hand

Joined: Jul 11, 2001
Posts: 15230

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

    Joined: Sep 05, 2003
    Posts: 234
    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.


    TTFN,<br /> <br />-bd-<br /> <br /><a href="http://www.amazon.com/exec/obidos/ASIN/0471449156/qid=1064343733/sr=2-1/ref=sr_2_1/002-8375300-3666449" target="_blank" rel="nofollow">Jakarta Pitfalls</a> | <a href="http://www.amazon.com/exec/obidos/tg/detail/-/0471146153/qid=1064343733/sr=1-2/ref=sr_1_2/002-8375300-3666449?v=glance&s=books" target="_blank" rel="nofollow">J2EE AntiPatterns</a> | <a href="http://www.amazon.com/exec/obidos/tg/detail/-/0471462071/qid=1064343733/sr=1-3/ref=sr_1_3/002-8375300-3666449?v=glance&s=books" target="_blank" rel="nofollow">Mastering JavaServer Faces</a> | <a href="http://bill.dudney.net/roller/page/bill" target="_blank" rel="nofollow">Blog</a> | <a href="http://www.jroller.com/page/BillDudney" target="_blank" rel="nofollow">Eclipse Blog</a> | <a href="http://www.sourcebeat.com/TitleAction.do?id=2" target="_blank" rel="nofollow">Eclipse 3 Live</a>
    Gregg Bolinger
    Ranch Hand

    Joined: Jul 11, 2001
    Posts: 15230

    Thanks Bill.
    Bill Dudney
    Author
    Ranch Hand

    Joined: Sep 05, 2003
    Posts: 234
    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

    Joined: Jul 11, 2001
    Posts: 15230

    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

    Joined: Jul 11, 2001
    Posts: 15230

    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??
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Managed-Bean question in JSF
     
    Similar Threads
    List box initialization through managed bean
    Accessing a managed bean from within another managed bean
    Problem to populate a selectOneListbox from a Java-Bean
    Not creating managed bean
    Obtaining an instance of a Managed Bean declared with Application Level Scope