public boolean checkLastName(String lastname) { studentList = studentBA.getAllStudents(); for (Iterator<Student> iterator = studentList.iterator(); iterator.hasNext(); ) { Student student = (Student) iterator.next(); if (student.getLastName().equals(lastname)) { return true; } } return false; }
public String createStudent() throws IOException { locale = FacesContext.getCurrentInstance().getViewRoot().getLocale(); // If locale is English if (locale == null || locale == Locale.ENGLISH) { locale = Locale.ENGLISH; inputStream = this.getClass().getResourceAsStream("/messages.properties"); if (checkFirstName(firstName) && checkLastName(lastName)) { String nameExisted = Props.getProperty(inputStream, "error.existed.name"); FacesMessage firstNameMessage = new FacesMessage(FacesMessage.SEVERITY_ERROR, null, nameExisted); FacesMessage lastNameMessage = new FacesMessage(FacesMessage.SEVERITY_ERROR, null, nameExisted); FacesContext.getCurrentInstance().addMessage("createForm:fNameInput", firstNameMessage); FacesContext.getCurrentInstance().addMessage("createForm:lNameInput", lastNameMessage); return null; } else { String createSuccess = Props.getProperty(inputStream, "success.create"); student = new Student(); int[] courseIds = new int[studentsCoursesIds.length]; student = new Student(); student.setFirstName(firstName); student.setLastName(lastName); student.setGender(gender); student.setAge(age); student.setMark(mark); for (int i = 0; i < courseIds.length; i++) { courseIds[i] = studentsCoursesIds[i]; } student.setCoursesId(courseIds); studentBA.createStudent(student, courseIds); FacesMessage successful = new FacesMessage(FacesMessage.SEVERITY_INFO, createSuccess, null); FacesContext.getCurrentInstance().addMessage(null, successful); return "Studentsinfo"; } } else { inputStream = this.getClass().getResourceAsStream("/messages_ar.properties"); if (checkFirstName(firstName) && checkLastName(lastName)) { String nameExisted = Props.getProperty(inputStream, "error.existed.name"); FacesMessage firstNameMessage = new FacesMessage(FacesMessage.SEVERITY_ERROR, null, nameExisted); FacesMessage lastNameMessage = new FacesMessage(FacesMessage.SEVERITY_ERROR, null, nameExisted); FacesContext.getCurrentInstance().addMessage("createForm:fNameInput", firstNameMessage); FacesContext.getCurrentInstance().addMessage("createForm:lNameInput", lastNameMessage); return null; } else { String createSuccess = Props.getProperty(inputStream, "success.create"); student = new Student(); int[] courseIds = new int[studentsCoursesIds.length]; student = new Student(); student.setFirstName(firstName); student.setLastName(lastName); student.setGender(gender); student.setAge(age); student.setMark(mark); for (int i = 0; i < courseIds.length; i++) { courseIds[i] = studentsCoursesIds[i]; } student.setCoursesId(courseIds); studentBA.createStudent(student, courseIds); FacesMessage successful = new FacesMessage(FacesMessage.SEVERITY_INFO, createSuccess, null); FacesContext.getCurrentInstance().addMessage(null, successful); return "Studentsinfo"; } } }