PDA

View Full Version : How to populate EXTJS combobox in Spring MVC framework



vivekajm
7 Nov 2009, 5:46 AM
did anyone know ho to populate EXTJS combobox using Spring MVC framework , I am trying to populate it using json object but i am getting an exception

[2009-11-07 19:15:59.962] at java.lang.Thread.run(Thread.java:619)
[2009-11-07 19:15:59.962] Caused by: java.lang.IllegalStateException: ApplicationObjectSupport instance [org.springframework.
web.servlet.view.json.JsonView: unnamed] does not run in an ApplicationContext


:((

Condor
7 Nov 2009, 6:42 AM
Not enough information.

Did you:
1. Create a controller that returns the data for the combobox in the model.
2. Create a view that returns the data in JSON format (or are you using the default JsonView).
3. Configure the controller to use the view.
4. Configure the handler mapping to the controller.

vivekajm
8 Nov 2009, 4:57 AM
Hi, Thanks for reply ,below is the code which I am using to populate the combobox please have a look on this

This is the controller which I am using

public class SearchAutoCompleteController implements Controller {

public ModelAndView handleRequest(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {

List HotelNames = searchHotels();
/*
* queryParam gives the text which is entered in textbox
*/
String queryParam=request.getParameter("query");
response.setContentType("text/json");
return new ModelAndView(new JsonView(),"HotelNames",convertToJSON(HotelNames));

}

//Convert java objects to JSON objects
private List convertToJSON(List objects) {
List jsonObjects = new ArrayList();
for (Object object : objects) {
jsonObjects.add(JSONSerializer.toJSON(object));
}
return jsonObjects;
}

private List searchHotels() {
List HotelNames = new ArrayList();
HotelNames.add(new HotelNamesBean(1, "Atlanta, GA, United States"));
HotelNames.add(new HotelNamesBean(2,
"Atlantic Beach, FL, United States"));
HotelNames.add(new HotelNamesBean(3, "Baraboo, WI, United States"));
HotelNames
.add(new HotelNamesBean(4, "Bartlesville, OK, United States"));
HotelNames.add(new HotelNamesBean(5,
"Barahona Airport, Dominican Republic"));
HotelNames.add(new HotelNamesBean(6, "Dedougou Airport, Burkina Faso"));
HotelNames.add(new HotelNamesBean(7, "Dean River Airport, Canada"));
HotelNames.add(new HotelNamesBean(8,
"Lackland Afb, Texas, United States"));
HotelNames.add(new HotelNamesBean(9, "Lachine, QC, Canada"));
return HotelNames;
}

}

This is the ExtJS combobox

var searchFieldStore = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({
url: 'searchautocompletecontroller'
}),
reader: new Ext.data.JsonReader({
root:'HotelNames'
},
[{name: 'id', mapping:'id'}, {name: 'name' , mapping:'name'}])
});


var searchFieldCombo=new Ext.form.ComboBox({
id:'searchField',
name: 'search',
fieldLabel: 'search',
store:searchFieldStore,
mode: 'remote',
displayField: 'name',
allowBlank: false,
valueField: 'id',
hiddenName : 'searchId',
anchor:'95%',
minchar:'3',
width:'100%',
hideTrigger:true,
typeAhead: true,
emptyText:'Enter City, Address, Airport, Point of Interest',
triggerAction: 'all'

});

This is the Controller Entry

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">

<!-- ========================= IMPORTS ============================== -->
<!-- model bean -->

<!-- <import resource="classpath:conf/domainService.xml"/>-->
<!-- <import resource="classpath:conf/modelBean.xml"/>-->

<!-- SelectHotelController -->
<!-- <bean name="MeetingRoomSearchController" class="com.ihg.apps.easymeetings.user.meetingroom.controller.MeetingRoomSearchController">
<property name="formView"><value>/user_home</value></property>
</bean>-->
<bean name="SearchLandingController" class="com.ihg.apps.easymeetings.user.searchlandingfield.controller.SearchLandingController">
</bean>
<bean name="SearchAutoCompleteController" class="com.ihg.apps.easymeetings.user.searchlandingfield.controller.SearchAutoCompleteController">
</bean>

<bean name="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<!-- <prop key="/meeting">MeetingRoomSearchController</prop> -->
<prop key="/searchlanding">SearchLandingController</prop>
<prop key="searchautocompletecontroller">SearchAutoCompleteController</prop>
</props>
</property>
</bean>

<!-- ========================= INTERNAL RESOURCE RESOLVER ========================= -->
<!-- <bean name="viewResolver" class="org.springframework.web.servlet.view.XmlViewResolver" >
<property name="viewClass"><value>org.springframework.web.servlet.view.json.JsonView</value></property>-->

<bean name="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass"><value>org.springframework.web.servlet.view.JstlView</value></property>
<property name="prefix"><value>/jsp</value></property>
<property name="suffix"><value>.jsp</value></property>
</bean>

</beans>

please suggest me where I am wrong ,I am kind of stuck ,please do suggest something

Thanks
Vivek Sharma