0
votes

I am using form:checkboxes and isn't working. I can check the items in the html and when i put submit, debbuging, i see the items i had checked arent in the list of my form, the list is empty

Form

public class 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;
}

Controller

@RequestMapping(value = "/manageStock", method = RequestMethod.GET) public ModelAndView controlarStockParaPasarAVenta(@RequestParam("getItem") long 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>

View Resolver

<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 Mapping

<?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>
1
can you show your configurations - kuhajeyan
i add my web.xml configuration, some else? ty! :) - evilkorona
your view resolvers , mapping - kuhajeyan
I did, something else? - evilkorona

1 Answers

0
votes

My form:checkboxes had to go over a list of entitys (ItemVenta) and save in the form's list elementos the entitys i checked. i googled answers and i found that i needed to add the method equals to my entity. It didn´t work. So intead of save entitys in the form´s list, now am i saving the ids of those entitys and it worked. I still go over a list of entitys.