Hi! I'm new to Spring, the forums and also speak Spanish, so please forgive me in advance for any mistakes with the post.
I have a MultiActionController that I'm trying to reuse for differents objects in my app. The idea is to have one super class, and then declare all subclasses only in xml, specifying the object that it controlls as a parameter. Is a little hard to explain, but I have all working, less one thing... I've a problem with command object
Right now, I have a method like this that works perfectly:
BUT, what I really need to have is something like this:Code:public ModelAndView onSaveForm(HttpServletRequest request, HttpServletResponse response, ItemCategory itemCategory) throws Exception { try { getMapper().insert(itemCategory); } catch (Exception e) { response.setStatus(700); return null; } ... more stuff }
When I do that change, the command is REALLY an Object, so I receive a ClassClastException when I try to cast it.Code:public ModelAndView onSaveForm(HttpServletRequest request, HttpServletResponse response, Object itemCategory) throws Exception { try { getMapper().insert((ItemCategory)itemCategory); //this cast will be made by reflexion, this is just an example } catch (Exception e) { response.setStatus(700); return null; } ... more stuff }
I've seen examples of this on the web, and no one is complaining about ClassClastException! what I'm doing wrong?? (per example: http://xmx1024.blogspot.com.ar/2006/...ller-with.html)
My form is declared like this:
my xml:Code:<form:form method="post" id="ItemCategory" name="ItemCategory" commandName="itemCategory" >
And this is the method wich puts the data on the form:Code:<bean id="ItemCategoryBean" class="ar.com.itesa.erp.item.bean.ItemCategory" scope="prototype" > </bean> <bean id="ItemCategory" class="ar.com.itesa.erp.item.controller.ItemCategoryController" scope="prototype" > <property name="mapper" ref="ItemCategoryMapper" /> <property name="basicObject" ref="ItemCategoryBean" /> <property name="viewsPath" value="items/configuration/category" /> </bean> <bean name="/ItemCategory.html" class="org.springframework.web.servlet.mvc.multiaction.MultiActionController"> <property name="methodNameResolver" ref="paramResolver" /> <property name="delegate" ref="ItemCategory" /> </bean>
Please help!Code:public ModelAndView onShowFormForNew(HttpServletRequest request, HttpServletResponse response) throws Exception { ModelAndView model = new ModelAndView(getViewsPath()+"/formNew"); model.addObject("itemCategory", new ItemCategory()); return model; }
Thank you in advance.
Lucy


Reply With Quote
