Results 1 to 3 of 3

Thread: [Spring 3.0.5] form:select causes a java.lang.IllegalStateException

  1. #1
    Join Date
    Jan 2013
    Posts
    2

    Default [Spring 3.0.5] form:select causes a java.lang.IllegalStateException

    Hello,
    I'm currently coding a web project for university using Spring 3.0.5 but I'm encountered a problem with a form in a .jsp file while causes an exception (see below). To be more specific, the problem seems to be with the <form:select> block as the form works if I remove it.

    I've spent the whole afternoon troubleshooting and trying various fixes without any results. I'd be very thankful if someone could help me solve this problem.

    Details
    The .jsp is supposed to display a form with two text fields to input date and a drop-down list to pick an employee from those present in the database. I've not copied the code to my implementation of the Workforce interface, which handles the employee list retrieval, but it works flawlessly. Any errors with the list must come from later on in the code.

    message java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'eInfo' available as request attribute

    description The server encountered an internal error that prevented it from fulfilling this request.

    exception

    org.apache.jasper.JasperException: java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'eInfo' available as request attribute
    org.apache.jasper.servlet.JspServletWrapper.handle JspException(JspServletWrapper.java:502)
    org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:424)
    org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:313)
    org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:260)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:717)
    org.springframework.web.servlet.view.InternalResou rceView.renderMergedOutputModel(InternalResourceVi ew.java:238)
    org.springframework.web.servlet.view.AbstractView. render(AbstractView.java:250)
    org.springframework.web.servlet.DispatcherServlet. render(DispatcherServlet.java:1047)
    org.springframework.web.servlet.DispatcherServlet. doDispatch(DispatcherServlet.java:817)
    org.springframework.web.servlet.DispatcherServlet. doService(DispatcherServlet.java:719)
    org.springframework.web.servlet.FrameworkServlet.p rocessRequest(FrameworkServlet.java:644)
    org.springframework.web.servlet.FrameworkServlet.d oGet(FrameworkServlet.java:549)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:617)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:717)

    root cause

    java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'eInfo' available as request attribute
    org.springframework.web.servlet.support.BindStatus .<init>(BindStatus.java:141)
    org.springframework.web.servlet.tags.form.Abstract DataBoundFormElementTag.getBindStatus(AbstractData BoundFormElementTag.java:174)
    org.springframework.web.servlet.tags.form.Abstract DataBoundFormElementTag.getPropertyPath(AbstractDa taBoundFormElementTag.java:194)
    org.springframework.web.servlet.tags.form.Abstract DataBoundFormElementTag.getName(AbstractDataBoundF ormElementTag.java:160)
    org.springframework.web.servlet.tags.form.Abstract DataBoundFormElementTag.autogenerateId(AbstractDat aBoundFormElementTag.java:147)
    org.springframework.web.servlet.tags.form.Abstract DataBoundFormElementTag.resolveId(AbstractDataBoun dFormElementTag.java:138)
    ...
    mViewEmployee.jsp
    Code:
    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <%@page isELIgnored="false"%>
    <%@taglib uri="http://www.springframework.org/tags/form" prefix="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=UTF-8">
    		<title>Caradeuc Pro Tools - View Employee Reports</title>
    	</head>
    	<body>
    		<form:form action="/projetIST/mViewEmployee" method="post" commandName="eInfo">
    			<form:select path="eid">
    				<form:option value="0" label="-- Select --" />
    				<form:options items="${employees}" itemValue="uid" itemLabel="name" />
    			</form:select>
    			<label for="start">Start date (DD/MM/YYYY): </label>
    			<input type="text" name="start"><br/>
    			<label for="end">End date (DD/MM/YYYY): </label>
    			<input type="text" name="end"><br/>
    			<input type="submit" value="Submit">
    		</form:form>
    	</body>
    </html>
    SpringController.java
    Code:
    package com.caradeuc.pro.spring;
    
    //Imports
    
    @Controller
    public class SpringController {
    	
    	Workforce wf; 
    	
    	public SpringController() {
    		wf = new WorkforceImpl();
    	}
    	
    	//
    	// Other mappings
    	//
    	
    	@RequestMapping(method=RequestMethod.GET, value="/mViewEmployee")
    	public ModelAndView showViewEmployeeForm() {
    		ViewEmployeeFormInfo eInfo = new ViewEmployeeFormInfo();
    		eInfo.setEmployees(wf.getListOfEmployees());
    		eInfo.setEnd("end");
    		eInfo.setStart("start");
    		ModelAndView mav = new ModelAndView("mViewEmployee", "eInfo", eInfo);
    		return mav;
    	}
    	
    	@RequestMapping(method=RequestMethod.POST, value="/mViewEmployee")
    	public String getViewEmployeeForm(@ModelAttribute("eInfo") ViewEmployeeFormInfo eInfo, BindingResult result, HttpServletRequest req) {
    		if (result.hasErrors())
    			return "mViewEmployee";  
    		System.out.println(eInfo.getEnd());
    		System.out.println(eInfo.getStart());
    		return null;
    	}
    }
    ViewEmployeeFormInfo.java
    Code:
    package com.caradeuc.pro.spring.models;
    
    import java.util.List;
    
    import com.caradeuc.pro.application.Employee;
    
    public class ViewEmployeeFormInfo {
    
    	private String start;
    	private String end;
    	private String eid;
    	private List<Employee> employees;
    	
    	
    	public String getStart() {
    		return start;
    	}
    	public void setStart(String start) {
    		this.start = start;
    	}
    	public String getEnd() {
    		return end;
    	}
    	public void setEnd(String end) {
    		this.end = end;
    	}
    	public String getEid() {
    		return eid;
    	}
    	public void setEid(String eid) {
    		this.eid = eid;
    	}
    	public List<Employee> getEmployees() {
    		return employees;
    	}
    	public void setEmployees(List<Employee> employees) {
    		this.employees = employees;
    	}	
    }
    Employee.java
    Code:
    package com.caradeuc.pro.application;
    
    public class Employee {
    	int uid;
    	String name;
    	
    	//Constructors
    	public Employee(int uid, String name) {
    		super();
    		this.uid = uid;
    		this.name = name;
    	}
    
    	public int getUid() {
    		return uid;
    	}
    
    	public void setUid(int uid) {
    		this.uid = uid;
    	}
    
    	public String getName() {
    		return name;
    	}
    
    	public void setName(String name) {
    		this.name = name;
    	}
    }
    Last edited by megahunter; Jan 23rd, 2013 at 02:23 PM.

  2. #2

    Default

    Code:
    @RequestMapping(method=RequestMethod.POST, value="/mViewEmployee")
    public String getViewEmployeeForm(@ModelAttribute("eInfo") ViewEmployeeFormInfo eInfo, BindingResult result, HttpServletRequest req) {
            if (result.hasErrors()) {
                return "theSameBiewName";
            }
    ....
    BindingResult result
    MANDATORY RIGHT AFTER
    @ModelAttribute("eInfo") ViewEmployeeFormInfo eInfo
    in signature parameters
    Best regards.

  3. #3
    Join Date
    Jan 2013
    Posts
    2

    Default

    Thanks, I've added that to my code but it does not affect the exception.
    Wouldn't I need to add a validator to make this useful though?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •