2016-11-28 1 views
0

私はフォーム:チェックボックスを使用していて、動作していません。私は、HTML内の項目をチェックすることができ、私は、debbugingを提出置くとき、私は私がチェックした項目は、私の形式のリストでアレント参照、リストは春の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設定を追加しましたか?タイ! :) – evilkorona

+0

あなたのビューリゾルバ、マッピング – kuhajeyan

答えて

0

マイ形式:チェックボックスがentitys(ItemVenta)のリストの上に行くとentitys ELEMENTOSフォームのリストに保存しなければなりませんでした私がチェックしました。私は答えをgoogledと私は私のエンティティにメソッドequalsを追加する必要があることがわかった。それはうまくいきませんでした。フォームのリストにエンティティを保存する代わりに、今はそれらのエンティティのIDを保存しています。私はまだエンティティのリストに行きます。

関連する問題