Olá pessoal,
Estou tentando fazer um cadastro simples utlizando o spring form, porém nao consigo submeter o formulario qdo clico no botão nao acontece nada, comecei a estudar o Spring a pouco tempo e estou tendo algumas dificuldades. Abaixo segue o código:
exemplo-servlet.xml
<bean name="/categoryForm.htm" class="com.exemplo.sbce.controller.CategoryFormController">
<property name="sessionForm" value="true"/>
<property name="commandName" value="category"/>
<property name="commandClass" value="com.exemplo.sbce.dataaccess.entity.Category"/>
<property name="formView" value="categoryForm"/>
<property name="successView" value="hello.htm"/>
<property name="categoryDAO" ref="categoryDAO"/>
</bean>
Classe de controle:
public class CategoryFormController extends SimpleFormController {
private CategoryDAO categoryDAO;
@Override
protected ModelAndView onSubmit(Object command) throws ServletException {
Category category = (Category) command;
categoryDAO.insert(category);
return new ModelAndView(new RedirectView(getSuccessView()));
}
@Override
protected Object formBackingObject(HttpServletRequest request) throws ServletException {
Category category = new Category();
category.setName("Bla");
category.setCategory(new Category());
return category;
}
public void setCategoryDAO(CategoryDAO categoryDAO) {
this.categoryDAO = categoryDAO;
}
}
categoryForm.jsp
<h1><fmt:message key="category.heading"/></h1>
<form:form method="post" commandName="category">
<table width="95%" bgcolor="f8f8ff" border="0" cellspacing="0" cellpadding="5">
<tr>
<td align="right" width="20%"> <fmt:message key="category.label_name"/></td>
<td width="20%">
<form:input path="name"/>
</td>
</tr>
<tr>
<td align="right" width="20%"> <fmt:message key="category.label_mae"/></td>
<td width="20%">
<form:input path="category"/>
</td>
</tr>
</table>
<br>
<input type="submit" align="center" value="Execute">
<br>
</form:form>
<a hello.htm"/>">Home</a>
Se alguem puder ajudar!