java - How to use beans in model attribute in Spring framework -


hello might it's silly question new in spring frame work. please help

web.xml

<display-name>demo name</display-name> <context-param>     <param-name>contextconfiglocation</param-name>     <param-value>/web-inf/applicationcontext.xml</param-value> </context-param> <listener>     <listener-class>org.springframework.web.context.contextloaderlistener </listener-class> </listener> 

applicationcontext.xml

<bean id="logininfo" class="com.saurabh.dto.logininfo"></bean> <bean id="contactinfo" class="com.saurabh.dto.contactinformation"></bean>  <bean id="userdto" class="com.saurabh.dto.userdto" scope="request"  abstract="false">     <property name="login" ref="logininfo"></property>     <property name="contact" ref="contactinfo"></property> </bean> 

controller

 @controller  public class logoncontroller {  @requestmapping(value = "/requestlogon.htm",method={requestmethod.post,requestmethod.get}) public string registeruser(@modelattribute("userdto") userdto user, bindingresult result, httpservletrequest request, httpservletresponse response,         httpsession session)throws exception{ 

now problem in controller userdto user, getting login property null according wiring have inject it. please explain issue..

you may better create userdto in method annotated @modelattribute rather specifying in spring applicationcontext.xml

@modelattribute("userdto") public userdto createmodel() {     userdto userdto = new userdto();     userdto.setlogin(new logininfo());     userdto.setcontact(new contactinformation());     return userdto; } 

that create , return new userdto object per request - spring bind form data to.


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -