2016-11-28 57 views
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> 
+0

你可以显示你的配置 – kuhajeyan

+0

我添加我的web.xml配置,其他? TY! :) – evilkorona

+0

您的视图解析器,映射 – kuhajeyan

回答

0

我的表单:复选框不得不去了实体来说(ItemVenta)的列表,并保存在窗体的列表elementos该实体我检查了。我GOOGLE了答案,我发现我需要添加方法等于我的实体。它没有工作。因此,在表格中列出了保存实体的内容,现在我可以保存这些实体的ID并且它可以工作。我仍然浏览实体列表。