+ 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.
+ */
+ public static boolean printFormErrors(HttpServletRequest req, PrintWriter out) {
+ Object o = req.getAttribute(SUBMIT_EXCEPTION);
+ if (o != null && (o instanceof PermamentFormException)) {
+ ((PermamentFormException) o).getCause().format(out, Page.getLanguage(req));
+ return false;
+ }
+ if (o != null && (o instanceof GigiApiException)) {
+ ((GigiApiException) o).format(out, Page.getLanguage(req));
+ }
+ return true;
+ }
+