Package org.appng.api

Interface ActionProvider<T>

  • Type Parameters:
    T - the bean type for this ActionProviders perform(...)-method. Must match MetaData.getBindClass() of the Datasource used by the Action

    public interface ActionProvider<T>
    An ActionProvider usually performs a CRUD-action on a domain object. The implementing class needs to be defined in the application's beans.xml. This bean is then being referenced in a concrete Action:
      <action id="update">
         <config>
             <title id="issue.update" />
             <params>
                 <param name="form_action" />
                 <param name="issueName" />
                 <param name="edit" />
             </params>
         </config>
         <condition expression="${form_action eq 'update' and not empty issueName}" />
         <datasource id="issue">
             <params>
                 <param name="issueName">${issueName}</param>
                 <param name="edit">${edit}</param>
             </params>
         </datasource>
         <bean id="issues">
             <option name="action" id="update" issue="${issueName}" />
         </bean>
     </action>
     
    There is no need to implement one ActionProvider per Action, since the Bean can be parameterized using different BeanOptions. So for example, the above defined bean could also be used for creating a new domain object, using another BeanOption:
     <action id="create">
         <config>
             <title id="issue.create" />
         </config>
         <condition expression="${form_action eq 'create'}" />
         <datasource id="new_issue">
             <params>
             <param name="form_action" />
             </params>
         </datasource>
         <bean id="issues">
             <option name="action" id="create" />
         </bean>
     </action>
     
    The distinction between create and update then can be done like this:
     
     if ("create".equals(options.getOptionValue("action", "id"))) {
         // create new domain object
     } else if ("update".equals(options.getOptionValue("action", "id"))){
         // update existing domain object
     }
     
    Author:
    Matthias Müller