Advertisement
Guest User

Untitled

a guest
Jun 6th, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.85 KB | None | 0 0
  1. <p:outputLabel for="txtClave" value="Clave"></p:outputLabel>
  2. <p:password id="txtClave" required="true" value="#{indexController.login.password}" />
  3.  
  4. <h:column />
  5. <p:commandButton icon="ui-icon-key" value="Iniciar Sesion" action="#{indexController.iniciarSesion()}"/>
  6. </h:panelGrid>
  7. <p:separator/>
  8. </h:form>
  9. </h:body>
  10. </html>
  11.  
  12. import com.mycompany.ejb.LoginFacade;
  13. import com.mycompany.ejb.LoginFacadeLocal;
  14. import com.mycompany.model.Login;
  15. import java.io.Serializable;
  16. import javax.annotation.PostConstruct;
  17. import javax.ejb.EJB;
  18. import javax.faces.application.FacesMessage;
  19. import javax.faces.context.FacesContext;
  20. import javax.faces.view.ViewScoped;
  21. import javax.inject.Named;
  22.  
  23. @Named
  24. @ViewScoped
  25. public class IndexController implements Serializable {
  26.  
  27. @EJB
  28. private LoginFacadeLocal EJBLogin;
  29.  
  30. private Login login;
  31.  
  32. @PostConstruct
  33. public void init() {
  34. login = new Login();
  35. }
  36.  
  37. public Login getLogin() {
  38. return login;
  39. }
  40.  
  41. public void setLogin(Login login) {
  42. this.login = login;
  43. }
  44.  
  45. public String iniciarSesion() {
  46. Login lg;
  47. String redireccion = null;
  48. try {
  49.  
  50. lg = EJBLogin.iniciarSesion(login);
  51.  
  52. if (lg != null) {
  53. redireccion = "/protegido/principal?faces-redirect=true";
  54.  
  55. } else {
  56. FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_WARN, "Aviso", "Failed Login"));
  57. }
  58.  
  59. } catch (Exception e) {
  60. FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_FATAL, "Aviso", "Error"));
  61.  
  62. //
  63. }
  64. return redireccion;
  65. }
  66.  
  67. package com.mycompany.model;
  68.  
  69. import java.io.Serializable;
  70. import javax.persistence.*;
  71. import javax.persistence.Entity;
  72. import javax.persistence.GeneratedValue;
  73. import javax.persistence.GenerationType;
  74. import javax.persistence.Id;
  75. import javax.persistence.Table;
  76.  
  77. @Entity
  78. @Table(name = "login")
  79. public class Login implements Serializable{
  80.  
  81. @Id
  82. @GeneratedValue(strategy = GenerationType.IDENTITY)
  83. private int id;
  84.  
  85. @Column(name = "username")
  86. private String username;
  87.  
  88. @Column(name = "password")
  89. private String password;
  90.  
  91. public int getId() {
  92. return id;
  93. }
  94.  
  95. public void setId(int id) {
  96. this.id = id;
  97. }
  98.  
  99. public String getUsername() {
  100. return username;
  101. }
  102.  
  103. public void setUsername(String username) {
  104. this.username = username;
  105. }
  106.  
  107. public String getPassword() {
  108. return password;
  109. }
  110.  
  111. public void setPassword(String password) {
  112. this.password = password;
  113. }
  114.  
  115. <html xmlns="http://www.w3.org/1999/xhtml"
  116. xmlns:h="http://xmlns.jcp.org/jsf/html"
  117. xmlns:p="http://primefaces.org/ui">
  118. <h:head>
  119. <title>DashBoard</title>
  120. </h:head>
  121. <h:body>
  122. <h:form>
  123.  
  124. <p:panel header="Inicio" footer="Desarrollado por : Miguel Mejia 2016">
  125.  
  126. <p:layoutUnit position="center">
  127. Welcome User : #{indexController.login.username} <br/>
  128. Date : #{currentDate.currentDate}
  129. </p:layoutUnit>
  130.  
  131. <p:menubar>
  132. <p:submenu label="Mantenimiento" icon="ui-icon-document">
  133. <p:menuitem value="CRUD : Estudiantes" url="laputamadre.jsp"/>
  134. <p:separator/>
  135. <p:menuitem value="CRUD : Ciudades" url="#"/>
  136. </p:submenu>
  137.  
  138. <p:submenu label="Reporte" icon="ui-icon-pencil">
  139. <p:menuitem value="Listado : Estudiantes" url="#"/>
  140. <p:separator/>
  141. <p:menuitem value="Listado : Ciudades" url="#"/>
  142. </p:submenu>
  143.  
  144. <p:submenu label="Configuracion" icon="ui-icon-help">
  145. <p:menuitem value="Mantenimiento : Perfiles" url="#"/>
  146. <p:separator/>
  147. <p:menuitem value="Mantenimiento : Usuarios" url="#"/>
  148. </p:submenu>
  149. </p:menubar>
  150. </p:panel>
  151.  
  152.  
  153. </h:form>
  154. </h:body>
  155. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement