Page 2 of 2 FirstFirst 12
Results 11 to 15 of 15

Thread: simpleformcontroller in tile

  1. #11
    Join Date
    Sep 2008
    Posts
    17

    Default

    That didn't seem to work either.... it seems like it's really bent on getting "command" from the request for some reason.

    Just to be sure, in my home controller, I manually set a search string.

    Code:
    				SearchForm s = new SearchForm();
    				s.setSearchString("searchstring");
    				WebUtils.setSessionAttribute(httpServletRequest, "command", s);
    And on the tile jsp (where the form is), I printed it out to make sure that part is working. And that worked fine (I commented out the form code).

    ${sessionScope.command.searchString}

    But as soon as i put the form code in there

    Code:
    	<form:form id="searchForm" commandName="command" name="searchForm" method="post" action="search">
    		<form:input id="searchString" path="searchString"/>
            <input type="submit" id="search" name="_eventId_search" value="Search" />    
    	</form:form>
    I start to get "Neither BindingResult nor plain target object for bean name 'command' available as request attribute". Completely ignores the "command" object in the session.

    What is not making sense to me is that how can we just say "action=search". How would it know what the form backing object is (it will after you submit, but when form is loading up)?

    Usually, we have an action, and we link to that action, so it looks in the config file and sees what the form backing object, and calls formbackingobject. But here we are just using it without ever going to the action in the config file first.

  2. #12
    Join Date
    Apr 2008
    Location
    Singapore
    Posts
    83

    Default

    looks like the command object has to be in request scope. so you can do a small change
    Code:
         <c:set var="command" value="${sessionScope.command}" scope="request"/>
    Code:
    <c:if test="${command eq null}">
         <c:set var="command" value="${sessionScope.command}" scope="request"/>
    </c:if>
    
    <form:form action="search" commandName="command">
    your seacch form inputs....
    </form:form>
    because when we do <c:set var="command" value="${sessionScope.command}"/>
    the command object is in page scope. so we can set it in request by scope="request"

    What is not making sense to me is that how can we just say "action=search". How would it know what the form backing object is (it will after you submit, but when form is loading up)?

    Usually, we have an action, and we link to that action, so it looks in the config file and sees what the form backing object, and calls formbackingobject. But here we are just using it without ever going to the action in the config file first.

    well looks like form looks for the command object in the request.

  3. #13
    Join Date
    Sep 2008
    Posts
    17

    Default

    that seems to be working! thanks for all your help.

    i wonder if there's a "real" spring way of doing this. but oh well, it is working for now... thanks again.

  4. #14
    Join Date
    Apr 2008
    Location
    Singapore
    Posts
    83

    Default

    putting the command object in the home controller is not appropriate, so what u can do is you can use a intercepter.,

    Intercept all requests that has the search form in the view.. and then put the command object if its not in the session.

  5. #15

    Default

    Can you please post full solution to this problem ? (your controller confifuration, tiles and Java code itself). What did you put for formView?

Tags for this Thread

Posting Permissions

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