Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <p:outputLabel for="txtClave" value="Clave"></p:outputLabel>
- <p:password id="txtClave" required="true" value="#{indexController.login.password}" />
- <h:column />
- <p:commandButton icon="ui-icon-key" value="Iniciar Sesion" action="#{indexController.iniciarSesion()}"/>
- </h:panelGrid>
- <p:separator/>
- </h:form>
- </h:body>
- </html>
- import com.mycompany.ejb.LoginFacade;
- import com.mycompany.ejb.LoginFacadeLocal;
- import com.mycompany.model.Login;
- import java.io.Serializable;
- import javax.annotation.PostConstruct;
- import javax.ejb.EJB;
- import javax.faces.application.FacesMessage;
- import javax.faces.context.FacesContext;
- import javax.faces.view.ViewScoped;
- import javax.inject.Named;
- @Named
- @ViewScoped
- public class IndexController implements Serializable {
- @EJB
- private LoginFacadeLocal EJBLogin;
- private Login login;
- @PostConstruct
- public void init() {
- login = new Login();
- }
- public Login getLogin() {
- return login;
- }
- public void setLogin(Login login) {
- this.login = login;
- }
- public String iniciarSesion() {
- Login lg;
- String redireccion = null;
- try {
- lg = EJBLogin.iniciarSesion(login);
- if (lg != null) {
- redireccion = "/protegido/principal?faces-redirect=true";
- } else {
- FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_WARN, "Aviso", "Failed Login"));
- }
- } catch (Exception e) {
- FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_FATAL, "Aviso", "Error"));
- //
- }
- return redireccion;
- }
- package com.mycompany.model;
- import java.io.Serializable;
- import javax.persistence.*;
- import javax.persistence.Entity;
- import javax.persistence.GeneratedValue;
- import javax.persistence.GenerationType;
- import javax.persistence.Id;
- import javax.persistence.Table;
- @Entity
- @Table(name = "login")
- public class Login implements Serializable{
- @Id
- @GeneratedValue(strategy = GenerationType.IDENTITY)
- private int id;
- @Column(name = "username")
- private String username;
- @Column(name = "password")
- private String password;
- public int getId() {
- return id;
- }
- public void setId(int id) {
- this.id = id;
- }
- 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;
- }
- <html xmlns="http://www.w3.org/1999/xhtml"
- xmlns:h="http://xmlns.jcp.org/jsf/html"
- xmlns:p="http://primefaces.org/ui">
- <h:head>
- <title>DashBoard</title>
- </h:head>
- <h:body>
- <h:form>
- <p:panel header="Inicio" footer="Desarrollado por : Miguel Mejia 2016">
- <p:layoutUnit position="center">
- Welcome User : #{indexController.login.username} <br/>
- Date : #{currentDate.currentDate}
- </p:layoutUnit>
- <p:menubar>
- <p:submenu label="Mantenimiento" icon="ui-icon-document">
- <p:menuitem value="CRUD : Estudiantes" url="laputamadre.jsp"/>
- <p:separator/>
- <p:menuitem value="CRUD : Ciudades" url="#"/>
- </p:submenu>
- <p:submenu label="Reporte" icon="ui-icon-pencil">
- <p:menuitem value="Listado : Estudiantes" url="#"/>
- <p:separator/>
- <p:menuitem value="Listado : Ciudades" url="#"/>
- </p:submenu>
- <p:submenu label="Configuracion" icon="ui-icon-help">
- <p:menuitem value="Mantenimiento : Perfiles" url="#"/>
- <p:separator/>
- <p:menuitem value="Mantenimiento : Usuarios" url="#"/>
- </p:submenu>
- </p:menubar>
- </p:panel>
- </h:form>
- </h:body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement