String targetId = targetComponent.getClientId(context);
Map attributes = component.getAttributes();
StringBuffer script = new StringBuffer(" new ");
// Build ajax function call
JSFunction submitSuggest = AjaxRendererUtils.buildAjaxFunction(
component, context, "RichFaces.Suggestion");
submitSuggest.addParameter(targetId);
submitSuggest.addParameter(component.getClientId(context));
submitSuggest.addParameter(component.getAttributes().get("onsubmit"));
Map options = AjaxRendererUtils.buildEventOptions(context, component);
options.put("popup", component.getClientId(context));
for (int i = 0; i < OPTIONS.length; i++) {
String option = OPTIONS[i];
Object value = attributes.get(option);
if (null != value) {
options.put(option, value);
}
}
// If ajax queue name not set, put clientId
String eventsQueue = (String) options.get("eventsQueue");
if (null == eventsQueue) {
options.put("eventsQueue", component.getClientId(context));
}
String onselect = (String) attributes.get("onselect");
if (null != onselect) {
JSFunctionDefinition function = new JSFunctionDefinition(
"suggestion");
function.addParameter("event");
function.addToBody(onselect);
options.put("onselect", function);
}
String onobjectchange = (String) attributes.get("onobjectchange");
if (null != onobjectchange) {
JSFunctionDefinition function = new JSFunctionDefinition(
"suggestion","event");
function.addToBody(onobjectchange);
options.put("onobjectchange", function);
}
if (component.getValueBinding("fetchValue") != null
|| attributes.get("fetchValue") != null) {
options.put("select", attributes.get("selectValueClass"));
}
UISuggestionBox suggestionBox = (UISuggestionBox) component;
options.put("usingSuggestObjects", suggestionBox.isUsingSuggestObjects());
// pass "zindex" attribute to js though the "options" attribute
options.put("zindex", suggestionBox.getZindex());
submitSuggest.addParameter(options);
script.append(submitSuggest.toScript()).append(";\n");
return "Richfaces.onAvailable('" + targetId + "', function() {" + script.toString() + "});";
}