GhForm.java 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package hello;
  2. import com.techempower.gemini.form.*;
  3. import com.techempower.gemini.*;
  4. /**
  5. * A specialization of Gemini's Form for GeminiHello.
  6. * <p>
  7. * By convention, all forms used by this application will use method="POST"
  8. * and POST is required for validation. A hidden nonce element is added
  9. * to every form to help prevent cross-site request forgery.
  10. *
  11. * @see com.techempower.gemini.form.Form
  12. *
  13. * Development history:
  14. * 2012-04-19 - mh - Created
  15. *
  16. * @author mhixson
  17. */
  18. public class GhForm
  19. extends Form
  20. {
  21. //
  22. // Member methods.
  23. //
  24. /**
  25. * Creates a new form.
  26. *
  27. * @param context The current context.
  28. * @param action The URL to submit to.
  29. * @param formName A name to give the form in case automatic naming
  30. * (generated by the context's command) is not
  31. * desirable.
  32. */
  33. public GhForm(Context context, String action, String formName)
  34. {
  35. super(context.getApplication(), formName, action, Form.POST);
  36. // Require that the method used to submit the form be POST. This
  37. // is done as a counter-measure against cross-site request forgery.
  38. addValidator(new FormPostRequired());
  39. // Add a nonce for the form. This is also an anti-CSRF measure.
  40. addElement(new FormNonce("nonce", context));
  41. }
  42. /**
  43. * Creates a new form. Names the form based on the current command.
  44. *
  45. * @param context The current context.
  46. * @param action The URL to submit to.
  47. */
  48. public GhForm(Context context, String action)
  49. {
  50. this(context, action, null);
  51. }
  52. @Override
  53. protected void onValidlySubmitted()
  54. {
  55. // Does nothing.
  56. }
  57. } // End GhForm.