public String create() { boolean valid = true; if (pollEJB.findByTitle(poll.getTitle()) != null) { // TODO: slugify/normalize poll title ControlUtil.reportError("title", "Poll with this title already exists"); valid = false; } Set<String> descriptions = Sets.newHashSet(Splitter.on(";").trimResults().omitEmptyStrings().split(answers)); if (descriptions.size() < 2) { ControlUtil.reportError("answers", "At least two answers should be specified"); valid = false; } if (!valid) { return null; } poll.setAuthor(loginControl.getCurrentUser()); pollEJB.persist(poll); for (String description : descriptions) { answerEJB.persist(new Answer(poll, description)); } // pollEJB.merge(poll); return "/polls/view.xhtml?id=" + poll.getId() + "&faces-redirect=true"; }
public void actionPerformed(ActionEvent e) { SessionContext context = SessionContext.getInstance(); selectOrderWindow = new SelectOrderWindow(); Boolean loggedIn = (Boolean) context.get(CustomerConstants.LOGGED_IN); ICustomerSubsystem customer = null; List<IOrder> orderList = null; // needs to log in if (!loggedIn.booleanValue()) { LoginControl loginControl = new LoginControl(selectOrderWindow, mainFrame, this); loginControl.startLogin(); } else { // already logged in customer = (ICustomerSubsystem) context.get(CustomerConstants.CUSTOMER); if (customer != null) orderList = customer.getOrderHistory(); List<String[]> displayableList = OrderUtil.extractOrderData(orderList); selectOrderWindow.updateModel(displayableList); mainFrame.getDesktop().add(selectOrderWindow); selectOrderWindow.setVisible(true); } }