Skip to content

Commit

Permalink
missing from example
Browse files Browse the repository at this point in the history
  • Loading branch information
Gavin King committed Nov 16, 2009
1 parent 27fefcf commit 4c1cdd0
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions reference/en-US/example.xml
Expand Up @@ -33,6 +33,26 @@ public class Credentials {
<h:commandButton value="Logout" action="#{login.logout}" rendered="#{login.loggedIn}"/>
</h:form>]]></programlisting>

<para>
Users are represented by a JPA entity:
</para>

<programlisting role="JAVA"><![CDATA[@Entity
public class User {
private @Id String username;
private String password;
public String getUsername() { return username; }
public void setUsername(String username) { this.username = username; }
public String setPassword(String password) { this.password = password; }
}]]></programlisting>

<para>
(Note that we're also going to need a <literal>persistence.xml</literal> file to configure the JPA persistence
unit containing <literal>User</literal>.)
</para>

<para>
The actual work is done by a session-scoped bean that maintains information about the currently logged-in user
and exposes the <literal>User</literal> entity to other beans:
Expand Down Expand Up @@ -91,8 +111,9 @@ public @interface UserDatabase {}]]></programlisting>
We need an adaptor bean to expose our typesafe <literal>EntityManager</literal>:
</para>

<programlisting role="JAVA"><![CDATA[public class UserDatabaseProducer {
@Produces @UserDatabase @PersistenceContext EntityManager userDatabase;
<programlisting role="JAVA"><![CDATA[class UserDatabaseProducer {
@Produces @UserDatabase @PersistenceContext
static EntityManager userDatabase;
}]]></programlisting>

<para>Now <literal>DocumentEditor</literal>, or any other bean, can easily inject the current user:</para>
Expand Down

0 comments on commit 4c1cdd0

Please sign in to comment.