Skip to content
This repository has been archived by the owner on Jul 17, 2019. It is now read-only.

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
anordin committed Oct 17, 2012
1 parent 28dae65 commit 3618628
Show file tree
Hide file tree
Showing 12 changed files with 206 additions and 215 deletions.
12 changes: 6 additions & 6 deletions faces-config.NavData
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scene Scope="Project" version="2">
<Scope Scope="Faces Configuration Only"/>
<Scope Scope="Project"/>
<Scope Scope="All Faces Configurations"/>
</Scene>
<?xml version="1.0" encoding="UTF-8"?>
<Scene Scope="Project" version="2">
<Scope Scope="Faces Configuration Only"/>
<Scope Scope="Project"/>
<Scope Scope="All Faces Configurations"/>
</Scene>
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package dat076.frukostklubben.bb;

import java.util.ArrayList;
Expand Down
35 changes: 14 additions & 21 deletions src/main/java/dat076/frukostklubben/bb/SignupBB.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package dat076.frukostklubben.bb;

import dat076.frukostklubben.ejb.CustomerEJB;
import dat076.frukostklubben.model.Customer;
import dat076.frukostklubben.ejb.UserEJB;
import dat076.frukostklubben.model.User;
import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;
import javax.faces.application.FacesMessage;
Expand All @@ -16,52 +12,49 @@
/**
*
* @author Julia
* Edited by: Anders, 2012-10-17
*/
@Named("signup")
@RequestScoped //created once for every request
@RequestScoped
public class SignupBB {

// ======================================
// = Attributes =
// ======================================

@EJB
CustomerEJB customerRegistry;

private Customer customer = new Customer();

UserEJB userRegistry;
private User user = new User();
private String passwdConfirm;

// ======================================
// = Public Methods =
// ======================================

public String doCreateCustomer() {
//log.log(Level.INFO, "New Customer Login {0} Passwd {1}", new Object[]{login, passwd});
try {
customer = customerRegistry.createCustomer(customer);
return "index.xhtml"; //or some confirmation page
user = userRegistry.createUser(user);
return "index.xhtml";
} catch (Exception e) {
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Bad Login name"));
return null; // Same page
return null; // Stay on same page
}
}

// ======================================
// = Getters & Setters =
// ======================================

public Customer getCustomer(){
return this.customer;
public User getUser(){
return this.user;
}

public void setCutomer(Customer customer){
this.customer = customer;
public void setUser(User user){
this.user = user;
}

public void passwdConfirm(String passwdConfirm){
this.passwdConfirm = passwdConfirm;
//do something real...
}

public String getpasswdConfirm(){
Expand Down
52 changes: 0 additions & 52 deletions src/main/java/dat076/frukostklubben/ejb/CustomerEJB.java

This file was deleted.

22 changes: 0 additions & 22 deletions src/main/java/dat076/frukostklubben/ejb/CustomerEJBRemote.java

This file was deleted.

49 changes: 49 additions & 0 deletions src/main/java/dat076/frukostklubben/ejb/UserEJB.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package dat076.frukostklubben.ejb;

import dat076.frukostklubben.model.User;
import java.util.List;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;

/**
*
* @author freein
* Edited by: Anders, 2012-10-17
*/
@Stateless
@LocalBean
public class UserEJB implements UserEJBRemote {

@PersistenceContext(unitName = "projectPU")
private EntityManager em;

@Override
public List<User> findUsers() {
TypedQuery<User> query = em.createNamedQuery("findAllUsers", User.class);
return query.getResultList();
}

@Override
public User findUserById(Long id) {
return em.find(User.class, id);
}

@Override
public User createUser(User user) {
em.persist(user);
return user;
}

@Override
public void deleteUser(User user) {
em.remove(em.merge(user));
}

@Override
public User updateUser(User user) {
return em.merge(user);
}
}
19 changes: 19 additions & 0 deletions src/main/java/dat076/frukostklubben/ejb/UserEJBRemote.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package dat076.frukostklubben.ejb;

import dat076.frukostklubben.model.User;
import java.util.List;
import javax.ejb.Remote;

/**
*
* @author freein
* Edited by: Anders, 2012-10-17
*/
@Remote
public interface UserEJBRemote {
List<User> findUsers();
User findUserById(Long id);
User createUser(User customer);
void deleteUser(User customer);
User updateUser(User customer);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,19 @@
/**
*
* @author Fredrik
* Edited by: Anders, 2012-10-17
*/
@Entity
@NamedQuery(name = "findAllCustomers", query = "SELECT c FROM Customer c")
public class Customer implements Serializable {
@NamedQuery(name = "findAllUsers", query = "SELECT u FROM User u")
public class User implements Serializable {

// Access level for user account.
public enum Access{
ADMIN,
USER
}


@Id @GeneratedValue
private long id;

Expand All @@ -31,15 +40,19 @@ public class Customer implements Serializable {
@OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
private Address address;
private String password;
private Access access;

public Customer(String firstName, String lastName, String mail, Address address) {


public User(String firstName, String lastName, String mail, Address address, Access access) {
this.firstName = firstName;
this.lastName = lastName;
this.mail = mail;
this.address = address;
this.access = access;
}

public Customer() {
public User() {
}

public long getId() {
Expand All @@ -52,9 +65,7 @@ public String getPassword() {

public void setPassword(String password) {
this.password = password;
}


}

public void setId(long id) {
this.id = id;
Expand Down Expand Up @@ -91,6 +102,12 @@ public Address getAddress() {
public void setAddress(Address address) {
this.address = address;
}



public void setAccess(Access access) {
this.access = access;
}

public Access getAccess() {
return access;
}
}
26 changes: 10 additions & 16 deletions src/main/webapp/pages/index.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,27 @@
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:ace="http://www.icefaces.org/icefaces/components">
<h:body>

<ui:composition template="/jsf/template/template.xhtml">
<ui:define name="content">
<article>
<header>
<h1>Search for a flight now!</h1>
</header>
<h:form>
<p><label for="from">From:</label><br/>
<p><label for="from">From:</label><br/>
<ace:textEntry id="from" value="#{search.flight.fromAirport}" styleClass="inputForm" /></p>
<p><label for="to">To:</label><br/>
<ace:textEntry id="to" value="#{search.flight.toAirport}" styleClass="inputForm" /></p>
<p><label for="price">Price:</label><br/>
<ace:textEntry id="price" value="#{search.flight.cost}" styleClass="inputForm" /></p>

<p><label for="to">To:</label><br/>
<ace:textEntry id="to" value="#{search.flight.toAirport}" styleClass="inputForm" /></p>

<p><label for="price">Price:</label><br/>
<ace:textEntry id="price" value="#{search.flight.cost}" styleClass="inputForm" /></p>

<ace:pushButton value="Search Travel" action="#{search.search}"/>

</h:form>
</article>
</ui:define>



</ui:composition>

</h:body>

</html>
</html>
16 changes: 8 additions & 8 deletions src/main/webapp/pages/signup.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,30 @@

<h:form>
<p><h:outputLabel for="mail" value="E-mail*:" /><br />
<h:inputText id="mail" value="#{signup.customer.mail}" size="10" required="required" autocomplete="off" class="inputForm"/></p>
<h:inputText id="mail" value="#{signup.user.mail}" size="10" required="required" autocomplete="off" class="inputForm"/></p>

<p><h:outputLabel for="firstName" value="First name*:" /><br />
<h:inputText id="firstName" value="#{signup.customer.firstName}" size="10" autocomplete="off" class="inputForm"/></p>
<h:inputText id="firstName" value="#{signup.user.firstName}" size="10" autocomplete="off" class="inputForm"/></p>

<p><h:outputLabel for="lastName" value="Last name*:" /><br />
<h:inputText id="lastName" value="#{signup.customer.lastName}" size="10" autocomplete="off" class="inputForm"/></p>
<h:inputText id="lastName" value="#{signup.user.lastName}" size="10" autocomplete="off" class="inputForm"/></p>

<p><h:outputLabel for="street" value="Street Address*:" /><br />
<h:inputText id="street" value="#{signup.customer.address.streetAddress}" size="10" autocomplete="off" class="inputForm"/></p>
<h:inputText id="street" value="#{signup.user.address.streetAddress}" size="10" autocomplete="off" class="inputForm"/></p>

<p><h:outputLabel for="zip" value="Zip Code*:" /><br />
<h:inputText id="zip" value="#{signup.customer.address.zip}" size="10" autocomplete="off" class="inputForm"/></p>
<h:inputText id="zip" value="#{signup.user.address.zip}" size="10" autocomplete="off" class="inputForm"/></p>

<p><h:outputLabel for="city" value="City*:" /><br />
<h:inputText id="city" value="#{signup.customer.address.city}" size="10" autocomplete="off" class="inputForm"/></p>
<h:inputText id="city" value="#{signup.user.address.city}" size="10" autocomplete="off" class="inputForm"/></p>

<p><h:outputLabel for="passwd" value="Password*:" /><br />
<h:inputSecret id="passwd" value="#{signup.customer.password}" size="10" autocomplete="off" class="inputForm"/></p>
<h:inputSecret id="passwd" value="#{signup.user.password}" size="10" autocomplete="off" class="inputForm"/></p>

<p><h:outputLabel for="passwdConfirm" value="Confirm Password*:" /><br />
<h:inputSecret id="passwdConfirm" value="#{signup.passwdConfirm}" size="10" autocomplete="off" class="inputForm"/></p>

<footer><h:commandButton id="register" value="Register" class="inputButton" action="#{signup.doCreateCustomer}" />
<footer><h:commandButton id="register" value="Register" class="inputButton" action="#{signup.doCreateUser}" />
<h:button outcome="signup" value="Clear" class="inputButton" /></footer>
</h:form>
</ui:define>
Expand Down
Loading

0 comments on commit 3618628

Please sign in to comment.