Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <h:form id="newuser" styleClass="regtable">
- <p:commandLink id="reg" value="Register"
- action="#{userBean.showReg}"
- process="reg"
- update=":newuser:regpan"/>
- <p:outputPanel id="regpan" style="padding: 60px; border: 20px; color: #F00;">
- <p:panelGrid id="usegrid" columns="2"
- rendered="#{userBean.regShow}"
- styleClass="regtable">
- <p:outputPanel/>
- <p:commandLink id="reghide" value="Hide"
- action="#{userBean.hideReg}"
- process="reghide"
- update="regpan"/>
- <f:facet name="header">
- Register
- </f:facet>
- <p:outputLabel/>
- <p:outputLabel id="useMessage" value="#{userBean.userMessage}"/>
- <p:outputLabel value="User Name: "/>
- <p:panel id="creds" styleClass="regtable">
- <p:inputText id="usern" value="#{userBean.proposedname}">
- <p:ajax event="keydown" listener="#{userBean.checkName}"
- process="creds"
- update="useMessage"/>
- </p:inputText>
- </p:panel>
- <p:outputLabel for="pw1" value="Password"/>
- <p:password id="pw1" value="#{userBean.password}"
- inline="true" match="pw2" feedback="true"/>
- <p:outputLabel for="pw2" value="Confirm Password"/>
- <p:password id="pw2" value="#{userBean.password}"/>
- <p:messages showDetail="true" autoUpdate="true"/>
- <p:outputLabel/>
- <p:outputLabel id="fnamelabel" value="First Name:"/>
- <p:inputText id="fname" value="#{userBean.firstname}"/>
- <p:outputLabel id="snamelabel" value="Surname:"/>
- <p:inputText id="sname" value="#{userBean.surname}"/>
- <p:commandLink id="makebutt"
- value="Make"
- action="#{userBean.registerUser}"
- process="usegrid"
- update="registered"/>
- </p:panelGrid>
- <p:panel id="registered" style="padding: 10px; border: 20px;">
- <p:outputLabel value="#{userBean.newUser.username}"/>
- <p:outputLabel value="#{userBean.newUser.firstname}"/>
- <p:outputLabel value="#{userBean.newUser.surname}"/>
- <p:commandLink id="makefinal" value="Accept"
- action="#{userBean.makeUser}"
- ajax="false"/>
- </p:panel>
- </p:outputPanel>
- </h:form>
- @Named(value = "userBean")
- @SessionScoped
- public class UserBean implements Serializable {
- @Inject
- private EnusersFacade facade;
- @Inject
- private EnprofileFacade proFacade;
- public UserBean() {
- }
- public String checkName() {
- allUsers = null;
- allUsers = facade.findAll();
- for (Enusers u : allUsers) {
- if (u.getUsername().equals(proposedname)) {
- System.out.println("user name: " + u.getUsername());
- userMessage = "User name " + u.getUsername()
- + " Already exists. Please choose another name";
- nameAvailable = false;
- break;
- } else {
- {
- nameAvailable = true;
- userMessage = "USER NAME" + proposedname + " AVAILABLE!";
- }
- }
- return null;
- }
- public void registerUser() {
- newUser = new Enusers(firstname, surname, username, password);
- username = getProposedname();
- newUser.setUsername(proposedname);
- password = encryptPassword(password);
- newUser.setPassword(password);
- newUser.setFirstname(firstname);
- newUser.setSurname(surname);
- }
- public String makeUser() {
- if (nameAvailable = true) {
- facade.create(newUser);
- } else {
- userMessage = "VALIDAION FAILED. Please try again and check that your uder name is not already taken";
- }
- selUser = newUser;
- return "/Main/Users/UserProfile";
- }
- <p:panelGrid id="userpro" columns="2">
- <p:outputLabel value="Salutation"/>
- <p:inputText value="#{profileBean.salutation}"/>
- <p:outputLabel value="First Name:"/>
- <p:inputText value="#{profileBean.proFirstName}"/>
- <p:outputLabel value="Surame:"/>
- <p:inputText value="#{profileBean.proSurname}"/>
- <p:outputLabel value="Date of Birth:"/>
- <p:calendar value="#{profileBean.dateofbirth}"/>
- <p:messages for="make" showDetail="true" autoUpdate="true"/>
- <p:commandLink id="make" value="Create"
- action="#{profileBean.checkProfile}"
- process="userpro make"
- update="usercheck"/>
- <p:messages id="msg" for="make"
- showDetail="true"
- autoUpdate="true"/>
- </p:panelGrid>
- <p:panelGrid id="usercheck" columns="2">
- <p:outputLabel value="Test"/>
- <p:outputLabel value="#{profileBean.newPro.firstname}"/>
- <p:outputLabel value="#{profileBean.newPro.surname}"/>
- <p:outputLabel value="#{profileBean.newPro.dateofbirth}"/>
- <p:commandLink id="accept" value="Accept"
- action="#{profileBean.makeProfile}"
- ajax="false"/>
- </p:panelGrid>
- </h:form>
- @Named(value = "profileBean")
- @RequestScoped
- public class ProfileBean {
- public ProfileBean() {
- }
- @Inject
- private EnprofileFacade proFacade;
- @Inject
- private UserBean uBean;
- private String salutation;
- private String proFirstName;
- private String proSurname;
- private Date dateofbirth;
- private Enprofile newPro;
- private Enusers selUser;
- public void checkProfile() {
- selUser = uBean.getSelUser();
- newPro = new Enprofile(salutation, proFirstName, proSurname, dateofbirth, selUser);
- salutation = getSalutation();
- newPro.setSalutation(salutation);
- proFirstName = getProFirstName();
- newPro.setFirstname(proFirstName);
- proSurname = getProSurname();
- newPro.setSurname(proSurname);
- dateofbirth = getDateofbirth();
- newPro.setDateofbirth(dateofbirth);
- selUser = getSelUser();
- newPro.setUser(selUser);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement