+ * if form data had problems or operations went wrong.
+ */
+ public abstract boolean submit(HttpServletRequest req) throws GigiApiException;
+
+ /**
+ * Calls {@link #submit(PrintWriter, HttpServletRequest)} while catching and
+ * displaying errors ({@link GigiApiException}), and re-outputing the form
+ * via {@link #output(PrintWriter, Language, Map)}.
+ *
+ * @param out
+ * the target to write the form and errors to
+ * @param req
+ * the request that this submit originated (for submit and for
+ * language)
+ * @return as {@link #submit(PrintWriter, HttpServletRequest)}: true, iff
+ * the form succeeded and the user should be redirected.
+ */
+ public boolean submitProtected(PrintWriter out, HttpServletRequest req) {
+ try {
+ boolean succeeded = submit(req);
+ if (succeeded) {
+ HttpSession hs = req.getSession();
+ hs.removeAttribute("form/" + getClass().getName() + "/" + csrf);
+ return true;
+ }
+ } catch (GigiApiException e) {
+ e.format(out, LoginPage.getLanguage(req));
+ }
+ output(out, LoginPage.getLanguage(req), new HashMap<String, Object>());
+ return false;
+ }
+
+ public boolean submitExceptionProtected(HttpServletRequest req) {
+ try {
+ if (submit(req)) {
+ HttpSession hs = req.getSession();
+ hs.removeAttribute("form/" + getClass().getName() + "/" + csrf);
+ return true;
+ }
+ return false;
+ } catch (PermamentFormException e) {
+ req.setAttribute(SUBMIT_EXCEPTION, e);
+ return false;
+ } catch (GigiApiException e) {
+ req.setAttribute(SUBMIT_EXCEPTION, e);
+ return false;
+ }
+ }
+
+ /**
+ * Prints any errors in any form submits on this request.
+ *
+ * @param req
+ * The request to extract the errors from.
+ * @param out
+ * the output stream to the user to write the errors to.
+ * @return true if no permanent errors occurred and the form should be
+ * reprinted.