First The JQuery Part, this method posts a JQUERY json model which is the options for a query, and then places the JSON results into a selectable list.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var options = { | |
address : address, | |
radius: radiusKm, | |
query : keyword | |
}; | |
$.ajax({ | |
type: 'POST', | |
url: '<c:url value="/publisher/place/query.json"/>', | |
dataType: 'json', | |
contentType: 'application/json', | |
data: JSON.stringify(options), | |
error : function(jqXHR, textStatus, errorThrown) { | |
console.error(textStatus); | |
jQuery('#welocally-post-error').html('ERROR : '+textStatus); | |
jQuery('#welocally-post-error').addClass('welocally-error error fade'); | |
}, | |
success : function(data, textStatus, jqXHR) { | |
jQuery('#welocally-post-error').removeClass('welocally-error'); | |
jQuery('#welocally-post-error').hide(); | |
jQuery('#welocally-post-error').html(''); | |
if(data.places != null && data.places.length == 0) { | |
jQuery('#welocally-post-error').append('<div class="welocally-context-help"></div>'); | |
jQuery('#welocally-post-error').append('Sorry no places were found that match your query, try again or add this as a new place.'); | |
jQuery('#welocally-post-error').addClass('welocally-update updated fade'); | |
} else if(data.places != null && data.places.length > 0) { | |
jQuery.each(data.places, function(i,item){ | |
console.log(JSON.stringify(item)); | |
jsonObjFeatures.push(item); | |
jQuery('#selectable').append(buildListItemForPlace(item,i)); | |
jQuery("#results").show(); | |
}); | |
} else if(data.places == null && data.errors != null) { | |
buildErrorMessages(data.errors); | |
} | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RequestMapping(value="/query", method = RequestMethod.POST) | |
public ModelAndView getPlacesByQueryJsonToo(@RequestBody String requestJson) | |
{ | |
logger.debug("getPlacesByQueryJson"); | |
ModelAndView mav = new ModelAndView("places"); | |
AjaxErrors eajax = new AjaxErrors(); | |
JSONObject jsonObject = null; | |
try { | |
jsonObject = new JSONObject(requestJson); | |
if (jsonObject !=null) { | |
String address = jsonObject.getString("address"); | |
String query = jsonObject.getString("address"); | |
String category = ""; | |
Long radius = jsonObject.getLong("radius"); | |
List<Place> places = | |
geoPlacesClient.findPlacesByQuery(address, query, category, radius); | |
mav.getModel().put("places", places); | |
mav.setViewName("places"); | |
} | |
} catch (JSONException e) { | |
logger.error("problem with request", e); | |
eajax.getErrors().add( | |
new AjaxError(103,"Problem parsing request.")); | |
} catch (Exception e) { | |
logger.error("problem with request", e); | |
eajax.getErrors().add( | |
new AjaxError(106,"Problem back at Welocally please report: "+e.getStackTrace()[0].toString().replace(".", " "))); | |
} | |
//if errors send them instead | |
if(eajax.getErrors().size()>0) { | |
try { | |
mav.getModel().put("mapperResult", makeJsonString(jacksonMapper, eajax)); | |
mav.setViewName("mapper-result"); | |
} catch (IOException e) { | |
logger.error("cannot serialize message", e); | |
} | |
} | |
return mav; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<bean id="velocityConfigurer" | |
class="org.springframework.web.servlet.view.velocity.VelocityConfigurer"> | |
<property name="resourceLoaderPath"> | |
<value>WEB-INF/vm/</value> | |
</property> | |
</bean> | |
<bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver" p:order="1"> | |
<property name="mediaTypes"> | |
<map> | |
<entry key="json" value="application/json"/> | |
<entry key="txt" value="text/plain"/> | |
</map> | |
</property> | |
<property name="defaultViews"> | |
<list> | |
<bean class="org.springframework.web.servlet.view.json.MappingJacksonJsonView" /> | |
</list> | |
</property> | |
<property name="viewResolvers"> | |
<list> | |
<!-- <bean id="localeResolver" class="org.springframework.web.servlet.i18n.CookieLocaleResolver" />--> | |
<bean class="com.welocally.admin.mvc.view.ExtensionAwareBeanNameViewResolver" | |
p:extension="json"/> | |
<bean class="com.sightlyinc.ratecred.admin.mvc.view.ExtensionAwareBeanNameViewResolver" | |
p:extension="txt"/> | |
<!-- <bean class="com.welocally.web.MobileBeanNameViewResolver" | |
p:mobileAgents="Android"/> --> | |
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> | |
<property name="prefix" value="/WEB-INF/views/"/> | |
<property name="suffix" value=".jsp"/> | |
</bean> | |
</list> | |
</property> | |
</bean> | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<bean id="places-json" | |
class="org.springframework.web.servlet.view.velocity.VelocityView"> | |
<property name="url" value="places-json.vm"/> | |
<property name="contentType" value="application/json"/> | |
</bean> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.welocally.admin.mvc.view; | |
import java.util.Locale; | |
import org.apache.log4j.Logger; | |
import org.springframework.beans.BeansException; | |
import org.springframework.context.ApplicationContext; | |
import org.springframework.core.Ordered; | |
import org.springframework.web.servlet.View; | |
import org.springframework.web.servlet.ViewResolver; | |
import org.springframework.web.servlet.view.BeanNameViewResolver; | |
public class ExtensionAwareBeanNameViewResolver extends BeanNameViewResolver | |
implements ViewResolver, Ordered { | |
static Logger logger = Logger.getLogger(ExtensionAwareBeanNameViewResolver.class); | |
private String extension; | |
public View resolveViewName(String viewName, Locale locale) | |
throws BeansException { | |
logger.debug("extension:"+extension+" view:"+viewName); | |
ApplicationContext context = getApplicationContext(); | |
String fullViewName = viewName + "-" + extension; | |
logger.debug("looking for view bean:"+fullViewName); | |
if (!context.containsBean(fullViewName)) { | |
// Allow for ViewResolver chaining. | |
return null; | |
} | |
View v = (View) context.getBean(fullViewName, View.class); | |
return v; | |
} | |
public void setExtension(String extension) { | |
this.extension = extension; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
#if(${placesSearchToken}) "token": "${placesSearchToken}",#end | |
"places": [ | |
#foreach($place in $places) | |
{ | |
"type": "$!{place.type}", | |
"name": "$!{place.name}", | |
#if(${place.latitude}) "latitude": $!{place.latitude}, | |
#end | |
#if(${place.longitude}) "longitude": $!{place.longitude}, | |
#end | |
"address": "$!{place.address}", | |
"city": "$!{place.city}", | |
"state": "$!{place.state}", | |
"postalCode": "$!{place.postalCode}", | |
"phone": "$!{place.phone}", | |
"website": "$!{place.website}", | |
#if(${place.categories}) | |
"categories":[ | |
#foreach($cat in $place.categories) "$cat"#if($velocityCount < $place.categories.size()),#end#end] | |
#end | |
}#if($velocityCount < $places.size()),#end | |
#end] | |
} |