public static void main(String[] args) { ApplicationContext factory = new FileSystemXmlApplicationContext("/bin/sample3/applicationContext2.xml"); MessageBean bean = (MessageBean) factory.getBean("messageBean"); bean.sayHello(); }
protected void popUpErrorMessage(String summaryMsg, String detailMsg, int step) { MessageBean mb = new MessageBean(); Resources r = new Resources(); mb.setSummary(r.getString(this, summaryMsg)); mb.setDetail(r.getString(this, detailMsg)); mb.setSeverity(FacesMessage.SEVERITY_ERROR); Effect e = new InputFieldErrorEffect(); getSamlV2HostedIdpCreateWizardBean().setSamlV2HostedCreateEntityInputEffect(e); getMessagesBean().addMessageBean(mb); }
// this method is called after the validation succeeded without any errors // so pass the valid data to the UserManager public String register() { if (this.um.addUser( userName, password1, firstName, lastName, streetName, city, zipCode, accountNo, bankCode)) { FacesContext fc = FacesContext.getCurrentInstance(); ResourceBundle bundle = fc.getApplication().getResourceBundle(fc, "m"); message.setText(bundle.getString("register_success"), null, FacesMessage.SEVERITY_INFO); return bundle.getString("home_page"); } return null; }
// checks if the user name is still available // if not, a message will be shown indicating that the // user name already exists public void validateUserName(FacesContext context, UIComponent toValidate, Object value) { String userName = (String) value; if (!this.um.isUserNameAvailable(userName)) { ((UIInput) toValidate).setValid(false); FacesContext fc = FacesContext.getCurrentInstance(); ResourceBundle bundle = fc.getApplication().getResourceBundle(fc, "m"); message.setText( bundle.getString("register_userExists"), bundle.getString("register_userExistsDetail"), FacesMessage.SEVERITY_ERROR, toValidate.getClientId()); } }
public static void main(String[] args) { ApplicationContext ctx = new ClassPathXmlApplicationContext("sample/beans.xml"); MessageBean bean = (MessageBean) ctx.getBean("targetBean"); bean.sayHello(); }
// validates the form to find any errors regarding the user input // "never trust any user" public void validate(ComponentSystemEvent event) { UIForm form = (UIForm) event.getComponent(); UIInput pw1 = (UIInput) form.findComponent("password1"); UIInput pw2 = (UIInput) form.findComponent("password2"); UIInput zipCode = (UIInput) form.findComponent("zip"); UIInput accountNo = (UIInput) form.findComponent("accountNo"); UIInput bankCode = (UIInput) form.findComponent("bankCode"); // check if a password has been entered if (pw1 == null || pw1.getValue() == null) { FacesContext fc = FacesContext.getCurrentInstance(); fc.renderResponse(); return; } // check further that both passwords are equal // if not, a message should be shown to the user telling him // that both passwords do not match if (!(pw1.getValue().equals(pw2.getValue()))) { pw1.setValue(""); pw2.setValue(""); FacesContext fc = FacesContext.getCurrentInstance(); ResourceBundle bundle = fc.getApplication().getResourceBundle(fc, "m"); message.setText( bundle.getString("register_passwordDifferent"), bundle.getString("register_passwordDifferentDetail"), FacesMessage.SEVERITY_ERROR, pw1.getClientId()); fc.renderResponse(); } String zip = (String) zipCode.getValue(); if (zip.length() > 8 || zip.length() < 4) { zipCode.setValue(""); FacesContext fc = FacesContext.getCurrentInstance(); ResourceBundle bundle = fc.getApplication().getResourceBundle(fc, "m"); message.setText( bundle.getString("register_zipError"), null, FacesMessage.SEVERITY_ERROR, zipCode.getClientId()); fc.renderResponse(); } String accountNumber = (String) accountNo.getValue(); if (accountNumber.length() > 12 || accountNumber.length() < 5) { accountNo.setValue(""); FacesContext fc = FacesContext.getCurrentInstance(); ResourceBundle bundle = fc.getApplication().getResourceBundle(fc, "m"); message.setText( bundle.getString("register_accountNoError"), null, FacesMessage.SEVERITY_ERROR, accountNo.getClientId()); fc.renderResponse(); } String bankcode = (String) bankCode.getValue(); if (bankcode.length() > 7 || bankcode.length() < 5) { bankCode.setValue(""); FacesContext fc = FacesContext.getCurrentInstance(); ResourceBundle bundle = fc.getApplication().getResourceBundle(fc, "m"); message.setText( bundle.getString("register_bankCodeError"), null, FacesMessage.SEVERITY_ERROR, bankCode.getClientId()); fc.renderResponse(); } }