Announcement Announcement Module

Spring Modules forum decommissioned in favor of Spring Extensions

As the Spring Modules project has been replaced by the Spring Extensions ( project, this forum has been decommissioned in favour of Spring Extensions one at:

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.

Costin Leau
SpringSource - Spring Training, Consulting, and Support - "From the Source"
See more
See less
unable to figure out JS error for first AJAX program Page Title Module
Move Remove Collapse
Conversation Detail Module
  • 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 -
    public class SearchEventHandler extends AbstractAjaxHandler {
    	public AjaxResponse loadOperators(AjaxActionEvent event) {
    		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", "");
    		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));
    		ReplaceContentAction action = new ReplaceContentAction("operators", options);
    		AjaxResponse response = new AjaxResponseImpl();
    		return response;
    And the JSP Code is
    					<table border="0" width="100%">
    								<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="${}"/>">
    												<spring:message code="${}"/>
    								<select name="operators" id="operators">
    Any suggestion, help to get out of this error?? i am clueless.


  • #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

    	<bean id="searchEventHandler" class="">
    	<bean id="ajaxInterceptor" class="org.springmodules.xt.ajax.AjaxInterceptor">
    	    <property name="handlerMappings">
    	            <prop key="/ajaxsearch.view">searchEventHandler</prop>
    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 -

            <property name="interceptors">
            		<ref bean="ajaxInterceptor"/>