12014Sep

GenericFormHandler And RepositoryFormHandler in ATG

GenericFormHandler And RepositoryFormHandler Classes In ATG

Both of these classes in ATG are used to create a custom form handler to deal with user input and repositories. But these two classes have different purposes in terms of creating new form handler. The difference is

GenericFormHandler

Custom form handlers should typically extend GenericFormHandler, which:

  • Is a subclass of GenericService
  • Includes standard form error handling

e.g – a search form, in this user will only put the search queries we don’t have to perform any create, delete and update operation so GenericFormHandler class will be used to create custom form handler in this case.

RepositoryFormHandler

This class we extends when we want to deal with the repositories for the data we have got from the form. Like we want to perform create , delete or update operations in repository. It includes logic that keeps the Java code from being dependent on a specific schema or repository definition.

e.g

Now we can use OurFormHanlder.create to create a new row in database without creating a new handle method. Also this class provides many hooks which can be use used for pre and post validation like preCreateItem and postCreateItem.

Do not override out-of-the-box methods to create, update, or delete items.

  • Muthu T BasePandian

    Can we use pre and post methods in genericFormHandler?

    • We have to extend it in our form handler so we have to write pre and post in custom form handler (if required) not in GenericFormHandler.