如何使用多个类别实现JSF primefaces自动完成?模型为Location
和City
。我想在单个<p:autoComplete>
中搜索城市和位置,如下例所示。
<p:autoComplete value="#{addEmployeeDetailsBean.selectedText}" completeMethod="#{addEmployeeDetailsBean.locatioAutoCompleteMethod}" maxResults="5" var="theme" itemLabel="#{theme}" itemValue="#{theme}" forceSelection="true" />
豆
private String selectedText;
public List<String> locatioAutoCompleteMethod(String query) {
autoCompletedList = new ArrayList<String>();
if (autoCompletedList != null) {
autoCompletedList.clear();
}
if (cityAutoList != null) {
for (CityModel cityObj : cityAutoList) {
if (cityObj.getCityName().toLowerCase().trim()
.startsWith(query.toLowerCase().trim())) {
autoCompletedList.add(cityObj.getCityName());
}}}
if (locationDetailsList != null) {
for (LocationModel locationObj : locationDetailsList) {
if (locationObj.getLocationName().toLowerCase().trim()
.startsWith(query.toLowerCase().trim())) {
autoCompletedList.add(locationObj.getLocationName() + ","
+ locationObj.getCityObj().getCityName());
}
}
}
return autoCompletedList;
}
城市模式:
public class CityModel implements Serializable{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "cityId", unique = true, nullable = false)
private Long cityId;
@Column(name = "cityName")
private String cityName;
}
位置模式:
public class LocationModel {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "locationId", unique = true, nullable = false)
private Long locationId;
@Column(name = "locationName")
private String locationName;
@ManyToOne
@JoinColumn(name = "cityObjId")
private CityModel cityObj;
@Column(name = "pinCode")
private String pinCode;
}