Announcement Announcement Module
Collapse
No announcement yet.
Including Search Form in Success View Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Including Search Form in Success View

    Hello,

    I am fairly new to Spring project. I am working on an application where I would like to include the search form jsp in the results view. Currently when I do this I get the following error:

    Code:
    java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'searchAccounts' available as request attribute
    Here is my bean configuration:

    Code:
    <bean name="/search.html" class="myapp.web.AccountSearchController">
      	    <property name="sessionForm" value="true"/>
            <property name="commandName" value="searchAccounts"/>
            <property name="commandClass" value="myapp.service.AccountSearch"/>
            <property name="validator">
                <bean class="myapp.service.AccountSearchValidator"/>
            </property>
            <property name="formView" value="accountSearch"/>
            <property name="successView" value="accountSearchResults"/>
        </bean>

    Here is the bit of JSP I am including in both views:
    Code:
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
    <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
    
    <form:form method="post" commandName="searchAccounts">
    
    <table valign="top" cellspacing="0" cellpadding="0" width="500" border="0">
    
        <tr>
            <td valign="top">
    
            <div class="border-title">Account Search</div>
    
            <div id="navhome">
            <div class="border">
            <div id="sidebarhome">
    
            
            <table id="form">
                <tr>
                    <td colspan="2">Search by Account ID or Domain Name. If
                    values are provided for both, only accounts matching both values
                    will be returned.</td>
                </tr>
    
                <tr>
                    <td colspan="2">&nbsp;</td>
                </tr>
    
                <tr>
                    <td align="right" valign="top"><form:label path="accountId">Account ID</form:label>:</td>
                    <td><form:input path="accountId" size="30"/></td>
                </tr>
                <c:set var="accountIdErrors"><form:errors path="accountId"/></c:set>
                <c:if test="${not empty accountIdErrors}">
                <tr>
                     <td>&nbsp;</td>
                     <td>${accountIdErrors}</td>
                </tr>
                </c:if>
                <tr>
                    <td align="right" valign="top"><form:label path="domainName">Domain Name</form:label>:</td>
                    <td><form:input path="domainName" size="30"/></td>
                </tr>
                <c:set var="domainNameErrors"><form:errors path="domainName"/></c:set>
                <c:if test="${not empty domainNameErrors}">
                <tr>
                     <td>&nbsp;</td>
                     <td>${domainNameErrors}</td>
                </tr>
                </c:if>
                <tr>
                    <td colspan="2">&nbsp;</td>
                </tr>
                <tr>
                    <td>&nbsp;</td>
                    <td><input type="submit" name="submit" value="Search">
                    </td>
                </tr>
            </table>
    
            </div>
            </div>
            </div>
    
            </td>
        </tr>
    </table>
    </form:form>
    And...here is my form controller class (less the imports):
    Code:
    public class AccountSearchController  extends SimpleFormController {
    
        protected final Log logger = LogFactory.getLog(getClass());
    
        public ModelAndView onSubmit(Object command, BindException errors) throws ServletException {
        	String accountId = ((AccountSearch) command).getAccountId();
        	String domainName = ((AccountSearch) command).getDomainName();
        	
        	logger.info("User provided search criteria...\n\tDomain Name: " + domainName + "\n\tAccountId: " + accountId);
    
        	//TODO do search
    
        	logger.info("returning from AccountSearch form view to " + getSuccessView());
    
        	return new ModelAndView(getSuccessView());
        }
    
        protected Object formBackingObject(HttpServletRequest request) throws ServletException {
        	AccountSearch accountSearch = new AccountSearch();
        	return accountSearch;
        }
    }

    Thanks in advance for your help!

    -aj
    Last edited by ajcoon; Nov 2nd, 2009, 02:23 PM. Reason: Scrubbing...

  • #2
    Answered here...

    http://stackoverflow.com/questions/1...n-success-view

    Comment

    Working...
    X