Spring struts and forms
I need to integrate struts with spring for a project.
I read the doc to ingrate struts and it's ok for classic beans but I have a probl开发者_如何转开发em for my forms.
I have a form like this in my struts-config.xml:
<form-beans>
<form-bean name="creationForm" type="org.apache.struts.validator.DynaValidatorActionForm" >
<form-property name="libelle" type="java.lang.String" />
<form-property name="quantite" type="java.lang.String" />
<form-property name="prix" type="java.lang.String" initial="10" />
</form-bean>
But it's strange for me to have a "type" in struts-config because it's spring which manages beans.
I don't found anything in the doc to manage forms by spring and the attribute "type" is mandatory for form in struts-config.
Someone can help me please ?
Hmm, in your struts-config, you set the type for your form (com.foo.bar.forms.UploadForm) like me.
My code work but it's strange struts manage form beans and spring manage other beans.
Concretely, I would like to know if it's possible to do that (I use your example) :
struts-config:
<form-beans>
<form-bean name="UploadForm" />
</form-beans>
action-servlet:
<bean name="UploadForm" class="com.foo.bar.forms.UploadForm" >
</bean>
I don't know exactly how it is that you had chosen to go about integrating the two frameworks but from experience I can tell you that it works.
for example my struts-config.xml has the following:
<struts-config>
<!-- ================== Form Beans ================ -->
<form-beans>
<form-bean name="UploadForm" type="com.foo.bar.forms.UploadForm" />
</form-beans>
<!-- ================== Action Mapping Definitions ================ -->
<action-mappings>
<action path="/pages/UploadFiles" name="UploadForm"
type="org.springframework.web.struts.DelegatingActionProxy" scope="request"
input="/pages/ImportFiles.jsp">
<forward name="success" path="/pages/SwitchView.do" />
</action>
<!-- ================================ Plugins ============================== -->
<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation"
value="/WEB-INF/action-servlet.xml, /WEB-INF/applicationContext.xml" />
</plug-in>
</struts-config>
my action-servlet.xml file contains the following bean definition:
<bean name="/pages/UploadFiles" class="com.foo.bar.actions.UploadFilesAction" />
This way Struts-1 retains control of the MVC but Spring "manages" the whole application.
Hope it helps
EDIT:
your web.xml should alos have the following:
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
<servlet>
<servlet-name>context</servlet-name>
<servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
EDIT 2:
Hmm, in your struts-config, you set the type for your form (com.foo.bar.forms.UploadForm) like me.
My code work but it's strange struts manage form beans and spring manage other beans.
I don't think it is strange at all...
Concretely, I would like to know if it's possible to do that
Yes
add the bean:
<bean name="CaseUpdateForm" class="com.foo.bar.forms.CaseUpdateForm" >
and convert the bean above to:
<bean name="/pages/UploadFiles" class="com.foo.bar.actions.UploadFilesAction">
<property name="updateForm" ref="UpdateForm" />
</bean>
精彩评论