Announcement Announcement Module
Collapse

Spring Modules forum decommissioned in favor of Spring Extensions

As the Spring Modules project has been replaced by the Spring Extensions (http://www.springsource.org/extensions) project, this forum has been decommissioned in favour of Spring Extensions one at:
http://forum.springsource.org/forumdisplay.php?f=44

Please see the Spring Extensions home page for a complete list of current projects in Java, .NET and ActionScript. You can also propose one if you want.

Cheers,
Costin Leau
SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
http://twitter.com/costinl
See more
See less
unable to figure out JS error for first AJAX program Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • unable to figure out JS error for first AJAX program

    I am trying my first Spring - AJAX handler program, but stuck with JS errors and not able to figure out the reason.
    My requirement is to load the values for a second combo box based on the value selected in the first combo box.
    The JS Error occurs as soon as I trigger the AJAX event on the onChange event of my first ComboBox. The error message just says - "Object Required" Line 415.

    The following is my handler code -
    Code:
    public class SearchEventHandler extends AbstractAjaxHandler {
    
    	public AjaxResponse loadOperators(AjaxActionEvent event) {
    		System.out.println("------------------------------------------");
    		HttpSession session = event.getHttpRequest().getSession();
    		SearchConfig config = (SearchConfig)session.getAttribute("searchConfig");
    		Map datatypesMap = (Map)session.getAttribute("datatypesMap");
    		SearchForm form = (SearchForm) event.getCommandObject();
    		String searchField = form.getSearchField1();
    		Datatype dataType;
    		String strDataType;
    		WebApplicationContext context = WebApplicationContextUtils.getRequiredWebApplicationContext(event.getHttpRequest().getSession().getServletContext());
    		List<Operation> operations;
    		Locale searchLocale = new Locale(config.getDisplayLocale());
    		List options = new LinkedList();
    		//The first option is just a dummy one:
    		Option first = new Option("-1", "");
    		options.add(first);
    		
    		if(!searchField.equals("")) {
    			strDataType = config.getDataTypeForField(searchField);
    			dataType = (Datatype)datatypesMap.get(strDataType);
    			operations = dataType.getOperations();
    			for(Operation operation: operations) {
    				Option option = new Option(operation.getName(), context.getMessage(operation.getName(), null, searchLocale));
    				options.add(option);
    			}
    		}
    		ReplaceContentAction action = new ReplaceContentAction("operators", options);
    		AjaxResponse response = new AjaxResponseImpl();
    		response.addAction(action);
    		return response;
    	}
    And the JSP Code is
    Code:
    					<table border="0" width="100%">
    						<tr>
    							<td>
    								<spring:bind path="searchForm.searchField1">
    									<select name="<core:out value="${status.expression}"/>" onChange="XT.doAjaxAction('loadOperators', this);">
    										<option value=""></option>
    										<core:forEach items="${searchConfig.searchFields}" var="field">
    											<option value="<core:out value="${field.name}"/>">
    												<spring:message code="${field.name}"/>
    											</option>
    										</core:forEach>
    									</select>
    								</spring:bind>
    							</td>							
    							<td>
    								<select name="operators" id="operators">
    								<option>------</option>
    								</select>
    							</td>					
    						</tr>			
    					</table>
    Any suggestion, help to get out of this error?? i am clueless.

    Regards,
    Anshumn

  • #2
    Just to update all so that the beginers do not make the same mistake as I did.

    I spent some time putting alert in the springxt.js file to know where the problem was. I reached till the handleStateChange function where responseXML is read. The responseXML.documentElement was coming as null. So the problem was that there was no response from the AjaxHandler side. Then, i added a system.out as my first statement to the AjaxHandler, which did not print. Then finally it came down to the configuration of the AjaxHandler in my context xml.

    I had configured the AjaxHandler in my context as

    Code:
    	<bean id="searchEventHandler" class="poc.search.controller.SearchEventHandler">
    	</bean>
    	<bean id="ajaxInterceptor" class="org.springmodules.xt.ajax.AjaxInterceptor">
    	    <property name="handlerMappings">
    	        <props>
    	            <prop key="/ajaxsearch.view">searchEventHandler</prop>
    	        </props>
    	    </property>
    	</bean>
    But what I had missed was to add the ajaxHandler in the interceptor list.
    so the things started working after i added the following configuration to the HandlerMapping -

    Code:
            <property name="interceptors">
            	<list>
            		<ref bean="ajaxInterceptor"/>
            	</list>
            </property>
    Regards,
    Anshumn

    Comment

    Working...
    X