0
我使用窗體:複選框,並不工作。我可以檢查的項目中的HTML,當我把提交,debbuging,我知道我已經檢查的項目在我的表單列表中的arent,該列表是空彈簧mvc - 窗體:複選框不要給我的項目
表
公共類PresupuestoForm {
private long id;
private List<ItemVenta> elementos;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public List<ItemVenta> getElementos() {
return elementos;
}
public void setElementos(List<ItemVenta> elementos) {
this.elementos = elementos;
}
控制器
@RequestMapping(值= 「/ manageStock」,方法= RequestMethod.GET) p ublic的ModelAndView controlarStockParaPasarAVenta(@RequestParam( 「的getItem」)長ID){
try{
Presupuesto p = this.presupuestoService.getPresupuesto(id);
PresupuestoForm form = new PresupuestoForm();
form.setId(p.getId());
List<ItemVenta> elementos = new ArrayList<ItemVenta>();
getItemsFromPresupuesto(p, elementos); // Method that fill the list elementos with some items
ModelAndView m = new ModelAndView("manageStock");
m.addObject("command",form);
m.addObject("elementos",elementos);
return m;
}catch(Exception e){
...
}
}
@RequestMapping(value = "/manageStockForm", method = RequestMethod.POST)
public Object manageStockPresupuestoForm(@ModelAttribute("manageStockForm") PresupuestoForm form, BindingResult result){
Presupuesto p = null;
try{
p = this.presupuestoService.getPresupuesto(form.getId());
for(ItemVenta i : form.getElementos()){
}
return "redirect:becomeVenta.html?getItem="+form.getId();
}catch(BussinesException e){
...
}catch(Exception e){
...
}
}
HTML
<table>
<tr style="display: none;">
<td><form:input path="id"/></td>
</tr>
<tr>
<td><div class="texto">
<form:checkboxes path="elementos" items="${elementos}" itemLabel="itemName" />
</div></td>
</tr>
<tr>
<td>
<input class="linkboton" type="submit" value="Submit"/>
</td>
</tr>
</table>
WEB.XML
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>SpringTiles</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
</web-app>
視圖解析器
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context3.0.xsd">
<context:component-scan base-package="controllers" />
<bean id="viewResolver"
class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass">
<value>
org.springframework.web.servlet.view.tiles2.TilesView
</value>
</property>
</bean>
<bean id="tilesConfigurer"
class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
<property name="definitions">
<list>
<value>/WEB-INF/tiles.xml</value>
</list>
</property>
</bean>
</beans>
ItemVenta映射
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD3.0//EN"
"http://hibernate.sourceforge.n/hibernate-mapping-3.0.dtd">
<hibernate-mapping default-access="field" default-cascade="save-update">
<class name="ventas.ItemVenta">
<id column="id" name="id">
<generator class="native" />
</id>
<property name="precio" />
<property name="nombre" />
<property name="cantidad" />
<property name="idItem" />
<property name="tipo" />
</class>
</hibernate-mapping>
你可以顯示你的配置 – kuhajeyan
我添加我的web.xml配置,其他? TY! :) – evilkorona
您的視圖解析器,映射 – kuhajeyan