Domanda

What is the difference between DynaActionForm and ActionForm ?

Someone said DynaActionForm is not really dynamic since you still have to restart the server after you re-configured the properties in the struts-config.xml file (or else modifications won't be picked up)

È stato utile?

Soluzione

In case of ActionForm,

We have to provide setters and getters whenever user adds a control. The same process is repeated again and again when user creates a view.

But, in case of DynaActionForm

It eliminates this burden and creates the form bean itself. This way user don't have to write setters and getters. No bean class is required for the DynaActionForm and we will declare the form beans as DynaActionForm type in struts-confing.xml. We will declare the properties and their type in the struts-config.xml

   <?xml version="1.0" encoding="ISO-8859-1" ?>

<!DOCTYPE struts-config PUBLIC
 "-//Apache Software Foundation//DTD Struts Configuration 1.0//EN"
 "http://jakarta.apache.org/struts/dtds/struts-config_1_0.dtd">

<struts-config>

  <!-- ========== Form Bean Definitions ================= -->
  <form-beans>

    <form-bean      name="submitForm"
                    type="hansen.playground.SubmitForm"/>

  </form-beans>

  <!-- ========== Action Mapping Definitions ============ -->
  <action-mappings>

    <action   path="/submit"
              type="hansen.playground.SubmitAction"
              name="submitForm"
              input="/submit.jsp"
              scope="request">
    <forward name="success" path="/submit.jsp"/>          
    <forward name="failure" path="/submit.jsp"/>          
    </action>

  </action-mappings>

</struts-config>

Update

struts-config.xml has two sections: the form-beans section, that lists the ActionForm beans, and the action-mappings.The mapping of the request (MyActionForm.do) to a specific Action and ActionForm class is done in the struts-config.xml file.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top