How to pass selected row data from datatable between two beans
<p>I've got a datatable with values in which I get from my <code>DB</code>.
In my class <code>myBean</code>, I've got an Variable of type <code>User</code> to store the selected row. It just can be selected one row. Now I want to call this Variable from an other bean which is called <code>printUser</code> to get the selected User.</p>

<p>But it always prints <code>null</code>.</p>

<p>View</p>

<pre><code>&lt;p:dataTable id="userDT" var="user" value="#{myBean.getUserList()}" selection="#{myBean.selectedUser}" 
             rowKey="#{user.id}" &gt;

    &lt;p:column selectionMode="single" style="width:16px;text-align:center"/&gt;

    &lt;p:column width="200" headerText="ID"&gt;
        &lt;h:outputText value="#{user.id}" /&gt;
    &lt;/p:column&gt;

    &lt;p:column width="200" headerText="Firstname"&gt;
        &lt;h:outputText value="#{user.firstname}" /&gt;
    &lt;/p:column&gt;

    &lt;p:column width="250" headerText="Lastname"&gt;
        &lt;h:outputText value="#{user.lastname}" /&gt;
    &lt;/p:column&gt;

&lt;/p:dataTable&gt;
</code></pre>

<p>myBean</p>

<pre><code>@Named(value = "myBean")
@ManagedBean
@SessionScoped
public class myBean implements Serializable {
    private static final long serialVersionUID = 1L;

    private User selectedUser = new User();

    public myBean() {

    }

    public List&lt;User&gt; getUserList() {

        ...    
    }

    public Patient getSelectedUser() {
        return selectedUser;
    }

    public void setSelectedUser(User selectedUser) {
        this.selectedUser= selectedUser;

    }

}
</code></pre>

<p>User.java</p>

<pre><code>public class User {

    private Integer id;
    private String firstname;
    private String lastname;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getFirstname() {
        return firstname;
    }

    public void setFirstname(String firstname) {
        this.firstname = firstname;
    }

    public String getLastname() {
        return lastname;
    }

    public void setLastname(String lastname) {
        this.lastname = lastname;
    }

}
</code></pre>

<p>printUser</p>

<pre><code>@Named(value = "printUser")
@ManagedBean
@RequestScoped
public class printUser {

    public printUser() {

    }

    public void getSelectedUserData(){
        myBean bean = new myBean();
        User user = new User();

        user = bean.getSelectedUser();

        System.err.println("UserID: " + user.getID());
    }

}
</code></pre>

<p>Hope you undertand my Problem.
Thanks alot
Excuse my English</p>