java ee – Displays the user name entered on all pages of my application (template)

Login authentication works perfectly, I now plan to put the name of the registered employee in the top corner of the screen, but I have searched and I have not found anything that works on my system yet . Take the courses

Official

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.validation.constraints.Size;

import org.hibernate.validator.constraints.NotEmpty;
import org.hibernate.validator.constraints.br.CPF;

@Entity
@Table (name = "tb_functions")
@NamedQueries ({
@NamedQuery (name = "Official.listar", query = "SELECT official FROM Official"),
@NamedQuery (name = "Official.searchCode", query = "official official official SELECT WHERE official.codigo =: code"),
@NamedQuery (name = "Official.log", query = "official official SELECT WHERE official.cpf =: cpf AND official.password = password"),
@NamedQuery (name = "Official.searchnameName", query = "Official SELECT FROM official official WHERE official.name =: name")
})
Public class Functional {

@GeneratedValue (strategy = GenerationType.AUTO)
id
@Column (name = "fun_codigo")
private long code;

@NotEmpty (message = "Enter the name")
@Column (name = "fun_name", length = 50, nullable = false)
private channel name;


@CPF (message = "Incorrect CPF")
@Column (name = "fun_cpf", length = 14, nullable = false, unique = true)
private String cpf;

@NotEmpty (message = "Enter the password")
@Size (min = 5, max = 15, message = "Your password must contain between 5 and 15 characters")
@Column (name = "fun_password", length = 50, nullable = false)
private channel password;

@NotEmpty (message = "Please enter a title")
@Column (name = "fun_funcao", length = 50, nullable = false)
private channel function;

public Long getCode () {
return code;
}

public void setCode (long code) {
this.codigo = code;
}

public String getNome () {
return the name;
}

public void setNome (String name) {
this.name = name;
}

public String getCpf () {
return cpf;
}

public void setCpf (String cpf) {
this.cpf = cpf;
}

public String getSenha () {
return password;
}

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

public String getFunction () {
return function;
}

public void setFunction (String Function) {
this.function = function;
}

@Override
public channel toString () {
"returning officer" [codigo=" + codigo + ", nome=" + nome + ", cpf=" + cpf + ", senha=" + senha + ", funcao="
                + funcao + "]";
}

@Override
public int hashCode () {
end int prime = 31;
int result = 1;
result = prime * result + ((code == null)? 0: code.hashCode ());
return the result;
}

@Override
public boolean equals (Object obj) {
if (this == obj)
return true;
if (obj == null)
returns false;
if (getClass ()! = obj.getClass ())
returns false;
Other official = (Official) obj;
if (code == null) {
if (other.codigo! = null)
returns false;
} else if (! codigo.equals (other.codigo))
returns false;
return true;
}
}

Official

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;

import br.sales.domain.Funtionary;
import br.com. Sales.util.HibernateUtil;

Public class FunctionAuthors {

empty public save (official official) {
Session session = HibernateUtil.getSessionFactory (). OpenSession ();

Transaction transaction = null;

try {
transaction = session.beginTransaction (); // opening the transaction
sessao.save (official);
transacao.commit (); // confirmation of the transaction

} catch (RuntimeException ex) {
if (transaction! = null) {
transaction.backback (); // cancel the transaction
}

}

finally {
session.close ();
}

}

@SuppressWarnings ("unchecked")
public list listing () {
Session session = HibernateUtil.getSessionFactory (). OpenSession ();

Listing official = zero;

try {

Query query = session.getNamedQuery ("Official.listar");
official = query.list ();

} catch (RuntimeException ex) {
launch ex;
}

finally {
session.close ();
}

official return;
}

public Official SearchPorcode (Long Code) {
Session session = HibernateUtil.getSessionFactory (). OpenSession ();

Official employee = null;

try {

Query query = session.getNamedQuery ("Official.searchCode");
query.setLong ("code", code);
official = (Official) query.uniqueResult ();

} catch (RuntimeException ex) {
launch ex;
}

finally {
session.close ();
}

official return;
}

official public fetchName (string name) {
Session session = HibernateUtil.getSessionFactory (). OpenSession ();

Official employee = null;

try {

Query query = session.getNamedQuery ("Official.searchName");
query.setString ("name", name);
official = (Official) query.uniqueResult ();

} catch (RuntimeException ex) {
launch ex;
}

finally {
session.close ();
}

official return;
}

No public exclude (official) {
Session session = HibernateUtil.getSessionFactory (). OpenSession ();

Transaction transaction = null;

try {
transaction = session.beginTransaction (); // opening the transaction
sessao.delete (official);
transacao.commit (); // confirmation of the transaction

} catch (RuntimeException ex) {
if (transaction! = null) {
transaction.backback (); // cancel the transaction
}

}

finally {
session.close ();
}

}

official public authenticate (String cpf, String password) {
Session session = HibernateUtil.getSessionFactory (). OpenSession ();
Official employee = null;

try {
// execute the request
Query query = session.getNamedQuery ("Official.log");
// receive the reported data
query.setString ("cpf", cpf);
query.setString ("password", password);
// Create the employee's request
official = (Official) query.uniqueResult ();
} catch (RuntimeException ex) {
launch ex;
} finally {
session.close ();
}
official return;
}

public void edit (official official) {
Session session = HibernateUtil.getSessionFactory (). OpenSession ();

Transaction transaction = null;

try {
transaction = session.beginTransaction (); // opening the transaction

sessao.update (official);
transacao.commit (); // confirmation of the transaction

} catch (RuntimeException ex) {
if (transaction! = null) {
transaction.backback (); // cancel the transaction
}

}

finally {
session.close ();
}

}
}

OfficialBean

import java.io.IOException;
import java.util.ArrayList;

import org.hibernate.Session;
import org.omnifaces.util.Faces;
import org.omnifaces.util.Messages;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;

import br.com. Sales.DAO.FunctionsDAO;

import br.sales.domain.Funtionary;
import br.com. Sales.util.JSFUtil;

@ManagedBean (name = "MBFunctionaries")
@ViewScoped
Public class FunctionBean {
official private employee = new official ();
Private DAO offices fdao = new DAO managers ();

Private list of paintings the articles;
Private list of paintings articlesFiltrados;
private channel action;
private channel name;
private long code;

public Long getCode () {
return code;
}

public void setCode (long code) {
this.codigo = code;
}

public String getAction () {
return action;
}

public void setAction (Chain Action) {
this action = action;
}

GetFunctional agent public () {

official return;
}

//
setFunctional Officer (Official) {public
this.functional = official;
}

public ArrayList getItens () {
return the articles;
}

public empty setItems (ArrayList articles) {
this.itens = items;
}

public ArrayList getItensFiltrados () {
return itFiltrados;
}

public void setItemsFiltrados (ArrayList Filtrados objects) {
this.itensFiltrados = itensFiltrados;
}

// @PostConstruct
public void prepareSearch () {

try {
Official DAO fdao = new official DAO ();
items = (ArrayList) fdao.listar ();

} catch (RuntimeException e) {
JSFUtil.AddressError ("ex.getMessage ()");
e.printStackTrace ();
}

}

public empty loadCadastro () {

try {

if (code! = null) {

Official DAO fdao = new official DAO ();

official = fdao.buscarPorCodigo (code);

} else {
official = new official ();

}

} catch (RuntimeException e) {
JSFUtil.AddressError ("ex.getMessage ()");
e.printStackTrace ();
}

}

public void loadName () {

try {

if (name! = null) {

Official DAO fdao = new official DAO ();

official = fdao.buscarPorName (name);

} else {
official = new official ();

}

} catch (RuntimeException e) {
JSFUtil.AddressError ("ex.getMessage ()");
e.printStackTrace ();
}

}

public void new () {
official = new official ();
}

public void save () {

try {
Official DAO fdao = new official DAO ();
fdao.salvar (official);

official = new official ();

JSFUtil.addressMessageSuccess ("Employee registered successfully!");

} catch (RuntimeException e) {
JSFUtil.AddressError ("ex.getMessage ()");
e.printStackTrace ();
}
}

public void delete () {
try {
fdao.excluir (official);

JSFUtil.AddMessageSuccess ("Employee successfully deleted!");

} catch (RuntimeException e) {
JSFUtil.AddressError ("You can not delete an employee with an associated sale!");
e.printStackTrace ();
}
}

public void authenticate () {
try {
// Get the user name and password of the user and call the DAO method to authenticate
official = fdao.authenticate (official.getCpf (), (official.getSenha ()));
// Check that the employee is null or different
if (official == null) {
JSFUtil.AddressError ("Invalid user or password");
} else {
// Redirect to the main page after the employee authentication.
FacesContext.getCurrentInstance (). GetExternalContext (). Redirect ("main.xhtml");
}
} catch (IOException error) {
error.printStackTrace ();
Messages.addGlobalError (erro.getMessage ());
}
}

public void edit () {
try {
Official DAO fdao = new official DAO ();
fdao.editar (official);

JSFUtil.AddMessageSuccess ("Employee edited successfully!");

} catch (RuntimeException e) {
JSFUtil.AddressError ("ex.getMessage ()");
e.printStackTrace ();
}
}
}

Model







    
    
    


    
    Cronus - Management Software


    

    

        

            
                
                    
                    
                        
                        
                    
                
            

            
            

            
                

                    
                        
                            
                            
                            
                        

                        
                            
                            
                            
                        

                        
                            
                        
                        

                    

                

            

            
            

            
                
                
                    
                

            
        

    


insert the description of the image here