import java.util.ArrayList;
import java.util.List;
import java.util.Iterator;
import java.util.Map;
import java.util.HashMap;
import java.util.Date;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import javax.faces.event.AjaxBehaviorEvent;
import javax.faces.event.FacesEvent;
import javax.faces.event.PhaseId;
import javax.el.ValueExpression;
import javax.faces.convert.Converter;
import javax.faces.component.behavior.Behavior;
import javax.el.MethodExpression;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import org.primefaces.event.SelectEvent;
import org.primefaces.util.Constants;
private static final Collection<String> EVENT_NAMES = Collections.unmodifiableCollection(Arrays.asList("blur","change","valueChange","click","dblclick","focus","keydown","keypress","keyup","mousedown","mousemove","mouseout","mouseover","mouseup","select", "itemSelect"));
public final static String STYLE_CLASS = "ui-inputfield ui-inputtextarea ui-widget ui-state-default ui-corner-all";
public final static String MOBILE_STYLE_CLASS = "ui-input-text ui-shadow-inset ui-body-inherit ui-corner-all";
@Override
public Collection<String> getEventNames() {
return EVENT_NAMES;
}
public Collection<String> getUnobstrusiveEventNames() {
return Collections.unmodifiableCollection(Arrays.asList("itemSelect"));
}
@Override
public int getCols() {
int cols = super.getCols();
return cols > 0 ? cols : 20;
}
@Override
public int getRows() {
int rows = super.getRows();
return rows > 0 ? rows : 3;
}
@Override
public void queueEvent(FacesEvent event) {
FacesContext context = getFacesContext();
Map<String,String> params = context.getExternalContext().getRequestParameterMap();
String eventName = params.get(Constants.RequestParams.PARTIAL_BEHAVIOR_EVENT_PARAM);
if(eventName != null && event instanceof AjaxBehaviorEvent) {
AjaxBehaviorEvent ajaxBehaviorEvent = (AjaxBehaviorEvent) event;
if(eventName.equals("itemSelect")) {
String selectedItemValue = params.get(this.getClientId(context) + "_itemSelect");
SelectEvent selectEvent = new SelectEvent(this, (Behavior) ajaxBehaviorEvent.getBehavior(), selectedItemValue);
selectEvent.setPhaseId(ajaxBehaviorEvent.getPhaseId());
super.queueEvent(selectEvent);
}
else {
//e.g. blur, focus, change
super.queueEvent(event);
}
}
else {
//e.g. valueChange, autoCompleteEvent
super.queueEvent(event);
}
}
private List suggestions = null;
public void broadcast(javax.faces.event.FacesEvent event) throws javax.faces.event.AbortProcessingException {
super.broadcast(event);
FacesContext facesContext = getFacesContext();
MethodExpression me = getCompleteMethod();
if(me != null && event instanceof org.primefaces.event.AutoCompleteEvent) {
suggestions = (List) me.invoke(facesContext.getELContext(), new Object[] {((org.primefaces.event.AutoCompleteEvent) event).getQuery()});
if(suggestions == null) {
suggestions = new ArrayList();
}
facesContext.renderResponse();
}
}
public List getSuggestions() {
return this.suggestions;
}