JSF2.0 Passing Value Objects Between Managed Beans

I already wrote a small JSF2.0 application using Weblogic 10.3.4, PrimeFaces and JQuery. Now I am considering converting our main web application to JSF2.0. He currently uses Weblogic 8.1, Java 1.4, and JSP. The question I have at the moment is the best way to transfer objects from one managed bean to another. Our application consists of many screens, but the general template is the link entered on the first screen, and when submitted it is viewed from the database, and the value object is filled (standard java bean). Then screen 2 returns, which is usually a form consisting of value object variables ready for editing.

Currently, all necessary objects are saved as an attribute in the HTTPServletRequest object on the first screen (within the class of the user-defined recording class), and then extracted from this on the next screen.

Is this another way to do this or is there a new "JSF" method that I skipped. I also thought about saving these Value objects in a user bean session (which we will have anyway), and then retrieve from there when necessary. I assume that a map containing Value objects would be the best way in this case?

+3
source share
1 answer

You can enter a managed bean into another managed bean on @ManagedProperty.

Suppose you have a bean session like this

@ManagedBean
@SessionScoped
public class User {
    // ...
}

And the request covered by a bean, like this one

@ManagedBean
@RequestScoped
public class Profile {

    @ManagedProperty(value="#{user}") // #{user} is the managed bean name
    private User user;

    @PostConstruct
    public void init() {
        // User is available here for the case you'd like to work with it
        // directly after bean construction.
    }

    public String save() {
        // User is available here as well, during action methods.
        userDAO.save(user);
    }

    // +getter +setter

}
+3

Source: https://habr.com/ru/post/1790723/


All Articles