Announcement Announcement Module
Collapse
No announcement yet.
Error : Neither BindingResult nor plain target object for bean name Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Error : Neither BindingResult nor plain target object for bean name

    Hi everyone! I can' t solve this problem please help me.

    I' ve the following error when I try to load the insertUser.jsp page.

    Code:
    java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'utente' available as request attribute
    	org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:141)
    insertUser.jsp
    Code:
    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
        pageEncoding="ISO-8859-1"%>
    <%@ taglib prefix="sf" uri="http://www.springframework.org/tags/form"%>
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Add User</title>
    </head>
    <body>
    
    <sf:form method="POST" action="addUser.htm" modelAttribute="utente">
    	
    	<table>
    		<tr>
    			<td>Email :</td>
    			<td><sf:input path="email"/>
    		</tr>
    		<tr>
    			<td>Nome :</td>
    			<td><sf:input path="nome"/>
    		</tr>
    		<tr>
    			<td>Cognome :</td>
    			<td><sf:input path="cognome"/>
    		</tr>
    		<tr>
    			<td>Password :</td>
    			<td><sf:input path="password"/>
    		</tr>
    		<tr>
    			<td><input type="submit" value="Inserisci Utente"></td>
    		</tr>
    	</table>
    
    </sf:form>
    
    </body>
    </html>
    My web.xml
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    
    <web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
             http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    
    	<servlet>
    		<servlet-name>PAE</servlet-name>
    		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    		<load-on-startup>1</load-on-startup>
    	</servlet>
    
    	<servlet-mapping>
    		<servlet-name>PAE</servlet-name>
    		<url-pattern>*.htm</url-pattern>
    	</servlet-mapping>
    
    	<welcome-file-list>
    		<welcome-file>pages/index.jsp</welcome-file>
    	</welcome-file-list>
    
    	<context-param>
    		<param-name>contextConfigLocation</param-name>
    		<param-value>/WEB-INF/PAE-servlet.xml</param-value>
    	</context-param>
    
    	<listener>
    		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    	</listener>
    
    </web-app>
    My dispatcher
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    
    <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-context-3.0.xsd">
    
    	<!-- the application context definition for the springapp DispatcherServlet -->
    	<!-- Definisce in che package si trovano i controller gestiti con le annotazioni -->
    	<context:component-scan base-package="controller" />
    
    	<!-- Mi consente di determinare un path ed un suffisso da utilizzare nel 
    		controller -->
    	<bean id="viewResolver"
    		class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    		<property name="viewClass"
    			value="org.springframework.web.servlet.view.JstlView"></property>
    		<property name="prefix" value="../pages/"></property>
    		<property name="suffix" value=".jsp"></property>
    	</bean>
    
    </beans>
    Controller
    Code:
    package controller;
    
    import orm.Utente;
    
    import org.springframework.context.ApplicationContext;
    import org.springframework.context.support.ClassPathXmlApplicationContext;
    import org.springframework.stereotype.Controller;
    import org.springframework.validation.BindingResult;
    import org.springframework.web.bind.annotation.ModelAttribute;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RequestMethod;
    import org.springframework.web.bind.annotation.SessionAttributes;
    import org.springframework.web.servlet.ModelAndView;
    
    import dao.UtenteDAO;
    
    @Controller
    public class addUserController {
    
    	@RequestMapping(value="addUser", method = RequestMethod.POST)
    	public String createUser (@ModelAttribute("utente") Utente utente, BindingResult result) {
    		
    		System.out.println("Email " + utente.getEmail() + " registrata!");
    //		ApplicationContext ctx =  new ClassPathXmlApplicationContext("beans.xml");
    //		UtenteDAO dao = (UtenteDAO) ctx.getBean("utenteDao");
    //		dao.insertUtente(utente);
    		
    		return "User registered!";
    	}
    }
    And the class Utente
    Code:
    package orm;
    
    import java.io.Serializable;
    import java.util.HashSet;
    import java.util.Set;
    
    import javax.persistence.AttributeOverride;
    import javax.persistence.AttributeOverrides;
    import javax.persistence.CascadeType;
    import javax.persistence.Column;
    import javax.persistence.Embedded;
    import javax.persistence.Entity;
    import javax.persistence.FetchType;
    import javax.persistence.GeneratedValue;
    import javax.persistence.GenerationType;
    import javax.persistence.Id;
    import javax.persistence.OneToMany;
    import javax.persistence.Table;
    
    @Entity
    @Table(name = "UTENTE")
    public class Utente implements Serializable{
    	
    	/**
    	 * 
    	 */
    	private static final long serialVersionUID = 1L;
    
    	@Id @GeneratedValue(strategy = GenerationType.AUTO)
    	@Column(name = "ID_UTENTE", nullable = false, unique = true)
    	private Long id;
    	
    	@Column(name = "EMAIL", length = 50, nullable = false, unique = true)
    	private String email;
    	
    	@Column(name = "PASSWORD", length = 10, nullable = false)
    	private String password;
    	
    	@Column(name = "NOME", length = 20, nullable = false)
    	private String nome;
    	
    	@Column(name = "COGNOME", length = 20, nullable = false)
    	private String cognome;
    	
    	@Embedded
    	@AttributeOverrides({
    		@AttributeOverride(name = "spazio_totale",
    						   column = @Column(name = "SPAZIO_TOTALE", nullable = false)),
    		@AttributeOverride(name = "spazio_utilizzato",
    						   column = @Column(name = "SPAZIO_UTILIZZATO", nullable = true))
    	})
    	private SpazioDropbox spazioDropbox;
    	
    	
    	/* RELAZIONE PROPRIETARIO CON LA TABELLA "FILE"  */
    	@OneToMany(cascade = {CascadeType.REMOVE, CascadeType.PERSIST, CascadeType.MERGE}, // Evito di fare la persistenza esplicitamente
    			   mappedBy = "proprietario",   // Applico la bidirezionalit√
    			   orphanRemoval = true,	// Quando elimino un oggeto File dalla lista elimino automaticamente tutti gli altri sui riferimenti presenti in altri oggetti
    			   fetch = FetchType.LAZY)
    	private Set<File> filePosseduti = new HashSet<File>();
    	
    	/* RELAZIONE CON LA TABELLA "FILE" MOLTI-A-MOLTI */
    	@OneToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE}, // Evito di fare la persistenza esplicitamente
    			   mappedBy = "utente",
    			   orphanRemoval = true,
    			   fetch = FetchType.LAZY)
    	private Set<CartellaCondivisa> cartelleCondivise = new HashSet<CartellaCondivisa>();
    	
    	/* RELAZIONE CON LA TABELLA COMMENTI */
    	@OneToMany(cascade = {CascadeType.REMOVE, CascadeType.PERSIST, CascadeType.MERGE},
    			   mappedBy = "utente",
    			   orphanRemoval = true,
    			   fetch = FetchType.LAZY)
    	private Set<Commento> commenti = new HashSet<Commento>();
    	
    	public Utente() {}
    	
    	public Utente(String email, String password, String nome, String cognome, SpazioDropbox spazioDropbox) {
    		
    		this.email = email;
    		this.password = password;
    		this.nome = nome;
    		this.cognome = cognome;
    		this.spazioDropbox = spazioDropbox;
    	}
    
    	public Long getId() {
    		return id;
    	}
    
    	public void setId(Long id) {
    		this.id = id;
    	}
    
    	public String getEmail() {
    		return email;
    	}
    
    	public void setEmail(String email) {
    		this.email = email;
    	}
    
    	public String getPassword() {
    		return password;
    	}
    
    	public void setPassword(String password) {
    		this.password = password;
    	}
    
    	public String getNome() {
    		return nome;
    	}
    
    	public void setNome(String nome) {
    		this.nome = nome;
    	}
    
    	public String getCognome() {
    		return cognome;
    	}
    
    	public void setCognome(String cognome) {
    		this.cognome = cognome;
    	}
    
    	public SpazioDropbox getSpazioDropbox() {
    		return spazioDropbox;
    	}
    
    	public void setSpazioDropbox(SpazioDropbox spazioDropbox) {
    		this.spazioDropbox = spazioDropbox;
    	}
    
    	public Set<File> getFilePosseduti() {
    		return filePosseduti;
    	}
    
    	public void setFilePosseduti(Set<File> filePosseduti) {
    		this.filePosseduti = filePosseduti;
    	}
    
    	public Set<CartellaCondivisa> getCartelleCondivise() {
    		return cartelleCondivise;
    	}
    
    	public void setCartelleCondivise(Set<CartellaCondivisa> cartelleCondivise) {
    		this.cartelleCondivise = cartelleCondivise;
    	}
    
    	public Set<Commento> getCommenti() {
    		return commenti;
    	}
    
    	public void setCommenti(Set<Commento> commenti) {
    		this.commenti = commenti;
    	}
    	
    	@Override
    	public boolean equals(Object o) {
    		if (o instanceof Utente) {
    			Utente u = (Utente) o;
    			if (this.email.equals(u.email) &&
    				this.password.equals(u.password))
    				return true;
    		}
    		return false;
    	}
    	
    	@Override
    	public int hashCode() {
    		return this.email.hashCode() + this.password.hashCode();
    	}
    	
    	@Override
    	public String toString() {
    		return email+","+password+","+nome+","+cognome+","+spazioDropbox.getSpazio_totale()+","+spazioDropbox.getSpazio_utilizzato();
    	}
    }
    The class Utente is annotated with Hibernate and it works. Sorry for my english!
Working...
X