Mail quite confusing, i try to give partial answers anyway

En l'instant précis du 22/03/07 12:33, Joe Reger, Jr. s'exprimait en ces
termes:
> Hi.
>
> I'm using MyFaces 1.1.5, Facelets 1.1.12, Java 6 and Tomcat 5.5.
>
> 1) page1.xhtml with backing bean Page1.java.  Page loads properly,
> displays a form of some sort.
>
> 2) User types some info into page1.xhtml and hits "Save" which calls
> Page1.save().
>
> 3) Page1.save() method returns a String.  JSF handles the page
> navigation and redirection.
>
> Problem: I can return "page2", to go to the second page in the flow. 
> But I need to initialize the backing bean for page2.xhtml which is
> called Page2.java.  If I simply use a faces-config.xml-defined
> navigation rule ("page2") I can't do this initialization... it'll call
> the page but won't call any methods to initialize.  So page2.xhtml
> displays for the user but they don't see the effect of the data they
> entered on page1.xhtml.
you don't need a backing bean per page, if page1 and page2 share same
datas, why not use the same backing bean for both?
>
> Constraint: Ajax4jsf only seems to work when I have a no-argument
> empty constructor, so I can't do backing bean initialization there.
no-arguments constructor is indeed part of the definition of the bean
concept :). If your bean are session scoped, they must be moreover
serializable. A class can only be serializable if it has a no argument
constructor.
>
> Question: In a commandLink I can specify #{page2.myInitMethod}
> (Facelets processes the EL and tells JSF where to go) which allows me
> to initialize my backing bean and return String "page2" so that the
> user gets the page.  But I can't do that in step 3) above... the
> backing bean can only return a String that's pre-defined in
> faces-config.xml.  Is there any way to route the browser from a
> backing bean to another page while specifying an initialization
> method?  Assuming I can't return "page2.myInitMethod".
Let JSF do the initialization stuff itself based on bean definitions
made in faces-config.xml. Btw, you can use managed properties if you
want you bean to know about each other. JSF does all this by itself
Example (myRequestBean.getOtherBean() will now return a JSF session
scoped managed bean):
        <managed-bean>
                <managed-bean-name>myRequestBean</managed-bean-name>
               
<managed-bean-class>com.company.SomeBean</managed-bean-class>
                <managed-bean-scope>request</managed-bean-scope>
                <managed-property>
                     <property-name>otherBean</property-name>
                    
<property-class>com.company.SomeOtherBean</property-class>
                     <value>#{mySessionBean}</value>
                 </managed-property>
        </managed-bean>
        <managed-bean>
                <managed-bean-name>mySessionBean</managed-bean-name>
               
<managed-bean-class>com.company.SomeOtherBean</managed-bean-class>
                <managed-bean-scope>session</managed-bean-scope>
        </managed-bean>

Moreover, again, you can make page1.java and page2.java a single bean.
Or you can have page1.java have a getter returning page2. In page2.xhtml
EL would then look like #{page1.page2.someProperty}
>
> Motivation: Slowly moving from a plain MyFaces implementation towards
> Seam which requires no-argument empty constructors.  Also looking to
> get Ajax4Jsf running on multi-screen wizard-like flows.  The app
> consists of about 50 backing beans and in the past I used java object
> constructors to initialize the beans, load stuff from the database,
> etc.  I'm sure I'm missing some basic page flow design pattern built
> into JSF and any help is appreciated.
>
I think you are stuck thinking you need a managed bean per form/page. A
JSF Managed bean is simply a bean that has a life duration (depending on
it's scope) and is made available to JSF component using EL expression.
The structure of your bean and their relation does not have to be tied
to your form. A form can combine several beans or a bean can be used by
several forms. Also, only beans you want directly available as EL value
need to be JSF managed. Objects returned by a getter of a JSF managed
bean do not need to be JSF managed.
> Thanks,
>
> Joe

Reply via email to