Announcement Announcement Module
Collapse
No announcement yet.
Unable to bind form fields to command. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Unable to bind form fields to command.

    Folks,

    I am new to springs, to head start I was trying to implement a search application. I am facing an issue with binding form parameters to the respective command object.

    In the following source I am trying to bind user input via search form to the respective bean in request scope. But alas, the value is never in place.

    I need your expert comments following are the code chunks of the flow.xml, form action configuration, search jsp and form bean.
    My web flow looks like this:
    I am using webflow-1.0.xsd
    Code:
    	<var name="searchBeanHolder" scope="flow" class="com.domain.SearchBeanHolder" />
    	
    	<start-state idref="askforcriteria" />
    	
    	<view-state id="askforcriteria" view="home">
    		<transition on="search" to="search" />
    	</view-state>
    	
    	<view-state id="search" view="searchForm">
    		<render-actions>
            	<action bean="searchFormAction" method="setupForm"/>
            </render-actions>
    	
    		<transition on="submitSearch" to="searchOrders">
    			<action bean="searchFormAction" method="bind"/>
    			<evaluate-action expression=
    				"flowScope.searchBeanHolder.setFormBean(requestScope.formBean)" />
    		</transition>
    	</view-state>
    
    	<action-state id="searchOrders">
    	    <action bean="searchOrderService"/>
    	    <transition on="success" to="showOrders" />
    	</action-state>
    	
    	<view-state id="showOrders" view="searchResultForm">
    		<transition on="search" to="search" />
    	</view-state>

    Search Form is as follows:

    Code:
    <form:form commandName="searchBeanHolder.formBean" action="flow.htm"> 								      	  	
    	<b>Trading Partner:</b><form:input path="tradingPartner"/></br>
    	<b>Request Number:</b><form:input path="requestNumber"/></br>
    	<b>Message Type:</b><form:input path="messageType"/></br>
    	<input type="hidden" name="_flowExecutionKey" value='<c:out value="${flowExecutionKey}"/>'/>
    	</br>
    	<input type="submit" class="button" name="_eventId_submitSearch" value="Submit"/>
    	<input type="submit" class="button" name="_eventId_cancel" value="Cancel"/>
    </form:form>
    Form Action is configured as follows:
    Code:
        <bean id="searchFormAction" class="org.springframework.webflow.action.FormAction">
                    <property name="formObjectName"  value="formBean"/>
                    <property name="formObjectClass" value="com.domain.SearchFormBean"/>
                    <property name="formObjectScope" value="REQUEST"/>
            </bean>
    Code:
    public class SearchBeanHolder implements Serializable
    {
    	private SearchFormBean formBean;
    
    	private List<OrderDetail> results;
    	
    	public SearchBeanHolder() 
    	{
    		formBean = new SearchFormBean();
    		results = new ArrayList<OrderDetail>();
    		System.out.println("[SearchBeanHolder]Inside Constructor ... ");
    	}
    
    	public SearchFormBean getFormBean() 
    	{
    		return formBean;
    	}
    
    	public void setFormBean(SearchFormBean formBean) 
    	{
    		this.formBean = formBean;
    	}
    
    	public List<OrderDetail> getResults() {
    		return results;
    	}
    
    	public void setResults(List<OrderDetail> results) {
    		this.results = results;
    	}
    	
    
    	public String toString() {
    		// TODO Auto-generated method stub
    		return super.toString()+" "+formBean+" "+results;
    	}
    }
    
    package com.domain;
    
    import java.io.Serializable;
    import java.util.List;
    
    public class SearchFormBean implements Serializable
    {
    	private String tradingPartner;
    	
    	private String requestNumber;
    	
    	private String messageType;
    	
    	
    	public SearchFormBean() {
    		tradingPartner = "";
    		requestNumber ="";
    		messageType = "";
    	}
    
    
    	public String getTradingPartner() 
    	{
    		return tradingPartner;
    	}
    	
    	public void setTradingPartner(String tradingPartner) 
    	{
    		this.tradingPartner = tradingPartner;
    	}
    	
    	public String getRequestNumber() 
    	{
    		return requestNumber;
    	}
    	
    	public void setRequestNumber(String requestNumber) 
    	{
    		this.requestNumber = requestNumber;
    	}
    	
    	public String getMessageType() 
    	{
    		return messageType;
    	}
    	
    	public void setMessageType(String messageType) 
    	{
    		this.messageType = messageType;
    	}
    	
    	public String toString() {
    		// TODO Auto-generated method stub
    		return super.toString()+" "+tradingPartner+" "+requestNumber+" "+messageType;
    	}
    	
    }
    Last edited by abhi_svits; Dec 11th, 2008, 12:20 AM.

  • #2
    formAction.bind->dataBinder.getAllowedFields

    Found that getAllowedFields returns null.
    Here's the logs:

    Binding allowed request parameters in map['formBean.requestNumber' -> 'def', 'formBean.tradingPartner' -> 'abc', 'formBean.me
    ssageType' -> 'ghi', '_eventId_submitSearch' -> 'Submit', '_flowExecutionKey' -> '_cFFAC65F9-A732-FB8E-DA84-346AB79FC5D1_kE69
    8A62F-C0BA-5589-A9AA-6E866CDD3A7F'] to form object with name 'formBean', pre-bind formObject toString = com.domain.SearchForm

    (Allowed fields are [null])

    Binding completed for form object with name 'formBean', post-bind formObject toString = com.domain.SearchFormBean@b1c468
    No results thus binded to formObject after processing.

    Comment


    • #3
      I traced the log and found the parameters name generated were formbean.messageType, formbean.tradingPartner and so on...
      I was expecting those names without formBean.... This was the reason I was not getting the value bind correctly.

      Comment

      Working...
      X