Results 1 to 2 of 2

Thread: Unable to display form facing IllegalStateException

  1. #1
    Join Date
    May 2011
    Posts
    2

    Default Unable to display form facing IllegalStateException

    Hi Guys,
    I am new to Spring MVC annotations.

    Please see the code and let me know what is the issue, if possible.
    It's just a simple form. I am trying to display a searchForm and based on that want to display the search results. The form is not getting displayed. When I try to hit the url in debug mode the s
    java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'search' available as request attributehowSearchForm() method is invoked but I am facing
    Please find my code below:


    SearchController.java

    @Controller
    @RequestMapping("/search")
    @SessionAttributes("search")
    public class SearchController {
    private ISearchService searchService;


    public void setSearchService(ISearchService searchService) {
    this.searchService = searchService;
    }

    @RequestMapping(method=RequestMethod.GET)
    public String showSearchForm(Model model){
    SearchCriteriaBean criteriaBean = new SearchCriteriaBean();
    model.addAttribute("criteriaBean",criteriaBean);
    return "searchForm";
    }

    public String onSubmit(@ModelAttribute("search") SearchCriteriaBean criteriaBean ){
    searchService.search(criteriaBean);
    return "redirect:searchForm";
    }
    }
    web.xml
    <servlet>
    <servlet-name>spring</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherSe rvlet</servlet-class>
    <!-- <init-param>
    <param-name>ConfigApplicationContext</param-name>
    <param-value>/WEB-INF/applicationContext.xml</param-value>
    </init-param> -->
    <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
    <servlet-name>spring</servlet-name>
    <url-pattern>/spring/*</url-pattern>
    </servlet-mapping>

    <listener>
    <listener-class>org.springframework.web.context.ContextLoade rListener</listener-class>
    </listener>
    <jsp-config>
    <taglib>
    <taglib-uri>http://java.sun.com/jsp/jstl/core</taglib-uri>
    <taglib-location>/WEB-INF/tld/c.tld</taglib-location>
    </taglib>
    </jsp-config>
    </web-app>
    spring-servlet.xml
    .....
    <bean id="viewResolver" class="org.springframework.web.servlet.view.Intern alResourceViewResolver"
    pr efix="/WEB-INF/jsp/" p:suffix=".jsp" />

    <bean id="searchService" class="org.krams.tutorial.service.SearchService"></bean>

    <!-- <bean name="/search"
    class="org.krams.tutorial.controller.SearchControl ler"
    p:searchService-ref="searchService"
    p:formView="searchForm"
    p:successView="searchForm" /> -->

    </beans>

    applicationContext.xml
    <!-- This required so that Spring can recognize our annotated beans -->
    <context:annotation-config />

    <!-- This required so that Spring can recognize certain annotations,
    For example @Controller and @Service. Make sure you set the correct base-package
    -->
    <context:component-scan base-package="org.krams.tutorial" />

    <!--
    This is responsible for automatically converting our custom POJO to JSON.
    Make sure you have Jackson in your classpath
    -->
    <mvc:annotation-driven />


    Please suggest me a way to remove this IllegalStateException.

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,632

    Default

    You refer to the bean as search put you are putting it in the model with the name 'criteriaBean'...

Posting Permissions

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