rich:suggestionbox only using last suggestion after token
jmanko Mar 31, 2011 11:28 AMI have a suggestion box component that searches for locations by city and zip, but the tokens attribute is not working properly. The only inout being search upon is the last item after the token. If I enter "new york" I get back all entries for city New York. If I enter "new york, 89" I only get entries with zip starting 89, which is NV. I did breakpoint, and the only events that fire are "89" and "". I'm using GFv3.1 and RFv3.3.3. Here is my code:
PAGE
<h:inputText id="cityStateSuggestionInput" value="#{controller.address.cityStateZip5County}" maxlength="100" size="50" />
<r:suggestionbox height="200" width="400"
usingSuggestObjects="true"
onselect="processSelection(#{r:component('cityStateSuggestion')}, #{r:component('cityStateSuggestionInput')}, #{r:component('city')}, #{r:component('state')}, #{r:component('zip5')}, #{r:component('county')});"
suggestionAction="#{sessionBean.citySuggestion}"
var="suggestion"
for="cityStateSuggestionInput"
id="cityStateSuggestion"
nothingLabel="No City Found"
minChars="2"
tokens=",">
<h:column>
<h:outputText value="#{suggestion.city}, #{suggestion.state} #{suggestion.zip} (#{suggestion.county} County)" />
</h:column>
</r:suggestionbox>
BACKING BEAN
public List<CityInfo> citySuggestion(Object searchKey){
if (searchKey == null || !(searchKey instanceof java.lang.String)) return null;
String searchTerm = ((String) searchKey).trim();
String city = "";
String zip = "";
List<CityInfo> cities = new ArrayList<CityInfo>();
Pattern cityPattern = Pattern.compile(CITY_REGEX_PATTERN, Pattern.CASE_INSENSITIVE);
Pattern zipPattern = Pattern.compile(ZIP_REGEX_PATTERN, Pattern.CASE_INSENSITIVE);
if (cityPattern.matcher(searchTerm).matches()) {
city = searchTerm;
}
if (zipPattern.matcher(searchTerm).matches()) {
zip = searchTerm;
}
cityPattern = null;
zipPattern = null;
if (city.isEmpty() && zip.isEmpty()) return null;
EntityManager em = emfInternal.createEntityManager();
Query query = em.createQuery("SELECT DISTINCT o FROM CityInfo o WHERE o.cityInfoPK.city LIKE :city AND o.cityInfoPK.zip LIKE :zip ORDER BY o.cityInfoPK.state, o.cityInfoPK.city, o.cityInfoPK.zip ");
query.setParameter("city", city.concat("%"));
query.setParameter("zip", zip.concat("%"));
query.setMaxResults(25);
try {
cities = (List<CityInfo>) query.getResultList();
} catch (Exception e){
}
query = null;
em.close();
em = null;
return cities;
}
ENTITY
public class CityInfo implements Serializable {
private static final long serialVersionUID = 1L;
@EmbeddedId
protected CityInfoPK cityInfoPK;
@Column(name = "County", length=25)
private String county;
@Column(name = "County_Code", length=3)
private String countyCode;
@Column(name = "zip", insertable=false, updatable=false)
private String zip;
@Column(name = "city", insertable=false, updatable=false)
private String city;
@Column(name = "state", insertable=false, updatable=false)
private String state;
}
faces-config.xml
<faces-config version="1.2"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd">
<application>
<view-handler>org.ajax4jsf.application.AjaxViewHandler</view-handler>
</application>
</faces-config>