Advertisement
Guest User

Untitled

a guest
Jan 21st, 2016
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.76 KB | None | 0 0
  1. <h:form id="newuser" styleClass="regtable">
  2. <p:commandLink id="reg" value="Register"
  3. action="#{userBean.showReg}"
  4. process="reg"
  5. update=":newuser:regpan"/>
  6. <p:outputPanel id="regpan" style="padding: 60px; border: 20px; color: #F00;">
  7.  
  8.  
  9. <p:panelGrid id="usegrid" columns="2"
  10. rendered="#{userBean.regShow}"
  11. styleClass="regtable">
  12. <p:outputPanel/>
  13. <p:commandLink id="reghide" value="Hide"
  14. action="#{userBean.hideReg}"
  15. process="reghide"
  16. update="regpan"/>
  17. <f:facet name="header">
  18. Register
  19. </f:facet>
  20. <p:outputLabel/>
  21. <p:outputLabel id="useMessage" value="#{userBean.userMessage}"/>
  22.  
  23. <p:outputLabel value="User Name: "/>
  24. <p:panel id="creds" styleClass="regtable">
  25. <p:inputText id="usern" value="#{userBean.proposedname}">
  26. <p:ajax event="keydown" listener="#{userBean.checkName}"
  27. process="creds"
  28. update="useMessage"/>
  29. </p:inputText>
  30. </p:panel>
  31.  
  32.  
  33. <p:outputLabel for="pw1" value="Password"/>
  34. <p:password id="pw1" value="#{userBean.password}"
  35. inline="true" match="pw2" feedback="true"/>
  36.  
  37.  
  38. <p:outputLabel for="pw2" value="Confirm Password"/>
  39. <p:password id="pw2" value="#{userBean.password}"/>
  40. <p:messages showDetail="true" autoUpdate="true"/>
  41. <p:outputLabel/>
  42.  
  43.  
  44. <p:outputLabel id="fnamelabel" value="First Name:"/>
  45. <p:inputText id="fname" value="#{userBean.firstname}"/>
  46.  
  47. <p:outputLabel id="snamelabel" value="Surname:"/>
  48. <p:inputText id="sname" value="#{userBean.surname}"/>
  49. <p:commandLink id="makebutt"
  50. value="Make"
  51. action="#{userBean.registerUser}"
  52. process="usegrid"
  53. update="registered"/>
  54.  
  55.  
  56. </p:panelGrid>
  57.  
  58. <p:panel id="registered" style="padding: 10px; border: 20px;">
  59. <p:outputLabel value="#{userBean.newUser.username}"/>
  60. <p:outputLabel value="#{userBean.newUser.firstname}"/>
  61. <p:outputLabel value="#{userBean.newUser.surname}"/>
  62. <p:commandLink id="makefinal" value="Accept"
  63. action="#{userBean.makeUser}"
  64. ajax="false"/>
  65. </p:panel>
  66.  
  67. </p:outputPanel>
  68.  
  69. </h:form>
  70.  
  71. @Named(value = "userBean")
  72. @SessionScoped
  73. public class UserBean implements Serializable {
  74.  
  75. @Inject
  76. private EnusersFacade facade;
  77.  
  78. @Inject
  79. private EnprofileFacade proFacade;
  80.  
  81. public UserBean() {
  82. }
  83.  
  84. public String checkName() {
  85. allUsers = null;
  86. allUsers = facade.findAll();
  87. for (Enusers u : allUsers) {
  88. if (u.getUsername().equals(proposedname)) {
  89. System.out.println("user name: " + u.getUsername());
  90.  
  91. userMessage = "User name " + u.getUsername()
  92. + " Already exists. Please choose another name";
  93. nameAvailable = false;
  94. break;
  95. } else {
  96. {
  97. nameAvailable = true;
  98. userMessage = "USER NAME" + proposedname + " AVAILABLE!";
  99. }
  100. }
  101.  
  102. return null;
  103. }
  104.  
  105.  
  106. public void registerUser() {
  107.  
  108. newUser = new Enusers(firstname, surname, username, password);
  109. username = getProposedname();
  110. newUser.setUsername(proposedname);
  111. password = encryptPassword(password);
  112. newUser.setPassword(password);
  113. newUser.setFirstname(firstname);
  114. newUser.setSurname(surname);
  115.  
  116. }
  117.  
  118. public String makeUser() {
  119.  
  120. if (nameAvailable = true) {
  121. facade.create(newUser);
  122. } else {
  123. userMessage = "VALIDAION FAILED. Please try again and check that your uder name is not already taken";
  124. }
  125.  
  126. selUser = newUser;
  127. return "/Main/Users/UserProfile";
  128. }
  129.  
  130. <p:panelGrid id="userpro" columns="2">
  131. <p:outputLabel value="Salutation"/>
  132. <p:inputText value="#{profileBean.salutation}"/>
  133.  
  134. <p:outputLabel value="First Name:"/>
  135. <p:inputText value="#{profileBean.proFirstName}"/>
  136.  
  137. <p:outputLabel value="Surame:"/>
  138. <p:inputText value="#{profileBean.proSurname}"/>
  139.  
  140. <p:outputLabel value="Date of Birth:"/>
  141. <p:calendar value="#{profileBean.dateofbirth}"/>
  142.  
  143. <p:messages for="make" showDetail="true" autoUpdate="true"/>
  144. <p:commandLink id="make" value="Create"
  145. action="#{profileBean.checkProfile}"
  146. process="userpro make"
  147. update="usercheck"/>
  148. <p:messages id="msg" for="make"
  149. showDetail="true"
  150. autoUpdate="true"/>
  151. </p:panelGrid>
  152.  
  153. <p:panelGrid id="usercheck" columns="2">
  154.  
  155. <p:outputLabel value="Test"/>
  156. <p:outputLabel value="#{profileBean.newPro.firstname}"/>
  157. <p:outputLabel value="#{profileBean.newPro.surname}"/>
  158. <p:outputLabel value="#{profileBean.newPro.dateofbirth}"/>
  159. <p:commandLink id="accept" value="Accept"
  160. action="#{profileBean.makeProfile}"
  161. ajax="false"/>
  162.  
  163. </p:panelGrid>
  164.  
  165. </h:form>
  166.  
  167. @Named(value = "profileBean")
  168. @RequestScoped
  169. public class ProfileBean {
  170.  
  171.  
  172. public ProfileBean() {
  173. }
  174.  
  175. @Inject
  176. private EnprofileFacade proFacade;
  177.  
  178. @Inject
  179. private UserBean uBean;
  180.  
  181. private String salutation;
  182. private String proFirstName;
  183. private String proSurname;
  184. private Date dateofbirth;
  185.  
  186. private Enprofile newPro;
  187. private Enusers selUser;
  188.  
  189. public void checkProfile() {
  190. selUser = uBean.getSelUser();
  191. newPro = new Enprofile(salutation, proFirstName, proSurname, dateofbirth, selUser);
  192.  
  193. salutation = getSalutation();
  194. newPro.setSalutation(salutation);
  195.  
  196. proFirstName = getProFirstName();
  197. newPro.setFirstname(proFirstName);
  198.  
  199. proSurname = getProSurname();
  200. newPro.setSurname(proSurname);
  201.  
  202. dateofbirth = getDateofbirth();
  203. newPro.setDateofbirth(dateofbirth);
  204.  
  205. selUser = getSelUser();
  206. newPro.setUser(selUser);
  207.  
  208. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement