Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
313 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version='1.0' encoding='UTF-8'?> | ||
<faces-config version="1.2" | ||
xmlns="http://java.sun.com/xml/ns/javaee" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd"> | ||
|
||
<application> | ||
<view-handler>com.sun.facelets.FaceletViewHandler</view-handler> | ||
</application> | ||
|
||
</faces-config> |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<web-app version="2.5" | ||
xmlns="http://java.sun.com/xml/ns/javaee" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> | ||
|
||
<display-name>Web Beans Login example</display-name> | ||
|
||
<!-- JSF --> | ||
|
||
<servlet> | ||
<servlet-name>Faces Servlet</servlet-name> | ||
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class> | ||
<load-on-startup>1</load-on-startup> | ||
</servlet> | ||
|
||
<servlet-mapping> | ||
<servlet-name>Faces Servlet</servlet-name> | ||
<url-pattern>*.jsf</url-pattern> | ||
</servlet-mapping> | ||
|
||
<context-param> | ||
<param-name>javax.faces.DEFAULT_SUFFIX</param-name> | ||
<param-value>.xhtml</param-value> | ||
</context-param> | ||
|
||
<session-config> | ||
<session-timeout>10</session-timeout> | ||
</session-config> | ||
|
||
<listener> | ||
<listener-class>org.jboss.webbeans.servlet.WebBeansListener</listener-class> | ||
</listener> | ||
|
||
</web-app> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | ||
<html xmlns="http://www.w3.org/1999/xhtml" | ||
xmlns:ui="http://java.sun.com/jsf/facelets" | ||
xmlns:h="http://java.sun.com/jsf/html" | ||
xmlns:f="http://java.sun.com/jsf/core" | ||
xmlns:s="http://jboss.com/products/seam/taglib"> | ||
|
||
<ui:composition template="template.xhtml"> | ||
<ui:define name="content"> | ||
<h:messages/> | ||
<h:form> | ||
<h:panelGrid columns="2" rendered="#{!login.loggedIn}"> | ||
<h:outputLabel for="username">Username:</h:outputLabel> | ||
<h:inputText id="username" value="#{credentials.username}"/> | ||
<h:outputLabel for="password">Password:</h:outputLabel> | ||
<h:inputText id="password" value="#{credentials.password}"/> | ||
</h:panelGrid> | ||
<h:commandButton value="Login" action="#{login.login}" rendered="#{!login.loggedIn}"/> | ||
<h:commandButton value="Logout" action="#{login.logout}" rendered="#{login.loggedIn}"/> | ||
</h:form> | ||
</ui:define> | ||
</ui:composition> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<html> | ||
<head> | ||
<meta http-equiv="Refresh" content="0; URL=home.jsf"> | ||
</head> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | ||
<html xmlns="http://www.w3.org/1999/xhtml" | ||
xmlns:ui="http://java.sun.com/jsf/facelets" | ||
xmlns:s="http://jboss.com/products/seam/taglib" | ||
xmlns:h="http://java.sun.com/jsf/html" | ||
xmlns:f="http://java.sun.com/jsf/core"> | ||
|
||
<head> | ||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> | ||
<title>Login</title> | ||
<link href="style/main.css" rel="stylesheet" type="text/css"/> | ||
<ui:insert name="head"/> | ||
</head> | ||
|
||
<body> | ||
|
||
<div id="container"> | ||
<div id="header"> | ||
|
||
</div> | ||
|
||
<div id="sidebar"> | ||
|
||
</div> | ||
|
||
<div id="content"> | ||
<ui:insert name="content"/> | ||
</div> | ||
|
||
<br style="clear:both"/> | ||
</div> | ||
|
||
</body> | ||
</html> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<project basedir="." name="Login Example Build" default="restart"> | ||
|
||
<property name="example.name" value="webbeans-login" /> | ||
|
||
<import file="../build.xml" /> | ||
|
||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<?xml version="1.0"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>org.jboss.webbeans.examples</groupId> | ||
<artifactId>parent</artifactId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<groupId>org.jboss.webbeans.examples</groupId> | ||
<artifactId>webbeans-login</artifactId> | ||
<packaging>war</packaging> | ||
<name>Web Beans Examples: Login</name> | ||
|
||
<pluginRepositories> | ||
<pluginRepository> | ||
<id>codehaus snapshot repository</id> | ||
<url>http://snapshots.repository.codehaus.org/</url> | ||
<releases> | ||
<enabled>true</enabled> | ||
</releases> | ||
</pluginRepository> | ||
</pluginRepositories> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.testng</groupId> | ||
<artifactId>testng</artifactId> | ||
<scope>test</scope> | ||
<classifier>jdk15</classifier> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.jboss.webbeans</groupId> | ||
<artifactId>webbeans-api</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>javax.faces</groupId> | ||
<artifactId>jsf-api</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.sun.facelets</groupId> | ||
<artifactId>jsf-facelets</artifactId> | ||
</dependency> | ||
|
||
<!-- <dependency> | ||
<groupId>org.jboss.el</groupId> | ||
<artifactId>jboss-el</artifactId> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>javax.el</groupId> | ||
<artifactId>el-api</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency>--> | ||
|
||
<dependency> | ||
<groupId>javax.el</groupId> | ||
<artifactId>el-ri</artifactId> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>javax.el</groupId> | ||
<artifactId>el-api</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
<build> | ||
<finalName>webbeans-login</finalName> | ||
</build> | ||
|
||
</project> | ||
|
18 changes: 18 additions & 0 deletions
18
login/src/main/java/org/jboss/webbeans/examples/login/Credentials.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package org.jboss.webbeans.examples.login; | ||
|
||
import javax.webbeans.Named; | ||
import javax.webbeans.RequestScoped; | ||
|
||
@RequestScoped @Named | ||
public class Credentials { | ||
|
||
private String username; | ||
private String password; | ||
|
||
public String getUsername() { return username; } | ||
public void setUsername(String username) { this.username = username; } | ||
|
||
public String getPassword() { return password; } | ||
public void setPassword(String password) { this.password = password; } | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
login/src/main/java/org/jboss/webbeans/examples/login/LoggedIn.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package org.jboss.webbeans.examples.login; | ||
|
||
import static java.lang.annotation.ElementType.FIELD; | ||
import static java.lang.annotation.ElementType.METHOD; | ||
import static java.lang.annotation.ElementType.TYPE; | ||
|
||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
import javax.webbeans.BindingType; | ||
|
||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target({TYPE, METHOD, FIELD}) | ||
@BindingType | ||
public @interface LoggedIn {} |
53 changes: 53 additions & 0 deletions
53
login/src/main/java/org/jboss/webbeans/examples/login/Login.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package org.jboss.webbeans.examples.login; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import javax.faces.application.FacesMessage; | ||
import javax.faces.context.FacesContext; | ||
import javax.webbeans.Current; | ||
import javax.webbeans.Named; | ||
import javax.webbeans.Produces; | ||
import javax.webbeans.SessionScoped; | ||
|
||
@SessionScoped @Named | ||
public class Login { | ||
|
||
@Current Credentials credentials; | ||
//@PersistenceContext EntityManager userDatabase; | ||
|
||
private User user; | ||
|
||
public void login() { | ||
|
||
List<User> results = /*userDatabase.createQuery( | ||
"select u from User u where u.username=:username and u.password=:password") | ||
.setParameter("username", credentials.getUsername()) | ||
.setParameter("password", credentials.getPassword()) | ||
.getResultList();*/ | ||
|
||
Arrays.asList( new User(credentials.getUsername(), "Your Name", credentials.getPassword()) ); | ||
|
||
if ( !results.isEmpty() ) { | ||
user = results.get(0); | ||
FacesContext.getCurrentInstance() | ||
.addMessage(null, new FacesMessage("Welcome, " + user.getName())); | ||
} | ||
|
||
} | ||
|
||
public void logout() { | ||
FacesContext.getCurrentInstance() | ||
.addMessage(null, new FacesMessage("Goodbye, " + user.getName())); | ||
user = null; | ||
} | ||
|
||
public boolean isLoggedIn() { | ||
return user!=null; | ||
} | ||
|
||
@Produces @LoggedIn User getCurrentUser() { | ||
return user; | ||
} | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
login/src/main/java/org/jboss/webbeans/examples/login/User.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package org.jboss.webbeans.examples.login; | ||
|
||
public class User { | ||
private String username; | ||
private String name; | ||
private String password; | ||
|
||
public User(String username, String name, String password) { | ||
super(); | ||
this.username = username; | ||
this.name = name; | ||
this.password = password; | ||
} | ||
|
||
public String getUsername() { | ||
return username; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setPassword(String password) { | ||
this.password = password; | ||
} | ||
|
||
} |