p:autoComplete,包含多个类别

时间:2016-04-04 06:48:10

标签: jsf primefaces autocomplete

如何使用多个类别实现JSF primefaces自动完成?模型为LocationCity。我想在单个<p:autoComplete>中搜索城市和位置,如下例所示。

Example

   <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; 

}

0 个答案:

没有答案