Author: nbelaevski
Date: 2008-03-17 23:27:37 -0400 (Mon, 17 Mar 2008)
New Revision: 6886
Modified:
trunk/ui/suggestionbox/src/main/java/org/richfaces/renderkit/html/SuggestionBoxRenderer.java
Log:
http://jira.jboss.com/jira/browse/RF-2344
Modified:
trunk/ui/suggestionbox/src/main/java/org/richfaces/renderkit/html/SuggestionBoxRenderer.java
===================================================================
---
trunk/ui/suggestionbox/src/main/java/org/richfaces/renderkit/html/SuggestionBoxRenderer.java 2008-03-18
03:27:32 UTC (rev 6885)
+++
trunk/ui/suggestionbox/src/main/java/org/richfaces/renderkit/html/SuggestionBoxRenderer.java 2008-03-18
03:27:37 UTC (rev 6886)
@@ -52,6 +52,7 @@
import org.ajax4jsf.resource.TemplateCSSResource;
import org.richfaces.component.AjaxSuggestionEvent;
import org.richfaces.component.UISuggestionBox;
+import org.richfaces.component.util.HtmlUtil;
import org.richfaces.skin.Skin;
import org.richfaces.skin.SkinFactory;
import org.richfaces.util.ReferenceMap;
@@ -87,6 +88,7 @@
*/
private final InternetResource[] additionalScripts = {
new org.ajax4jsf.javascript.PrototypeScript(),
+ getResource("/org/richfaces/renderkit/html/scripts/available.js"),
new org.ajax4jsf.javascript.SmartPositionScript(),
getResource("/org/richfaces/renderkit/html/scripts/browser_info.js"),
getResource("scripts/scriptaculo.js"),
@@ -336,8 +338,19 @@
+ " not found in SuggestionBox " + component.getId());
}
} else {
- throw new FacesException("Component SuggestionBox "
- + component.getId() + " don't have property 'for'
");
+ UIComponent parent = component.getParent();
+ if (parent != null) {
+ if (HtmlUtil.shouldWriteId(parent)) {
+ return parent;
+ } else {
+ throw new FacesException("SuggestionBox cannot be attached to component
having id: " +
+ component.getId() + " because its client identifier is likely to not be
written into browser! " +
+ "Please try to set id manually!");
+ }
+ } else {
+ throw new FacesException("Parent component is null for SuggestionBox "
+
+ component.getId());
+ }
}
}
@@ -350,13 +363,15 @@
*/
private String getScript(final FacesContext context,
final UIComponent component) {
+ UIComponent targetComponent = getTarget(component);
+ 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");
- UIComponent targetComponent = getTarget(component);
- submitSuggest.addParameter(targetComponent.getClientId(context));
+ submitSuggest.addParameter(targetId);
submitSuggest.addParameter(component.getClientId(context));
submitSuggest.addParameter(component.getAttributes().get("onsubmit"));
Map options = AjaxRendererUtils.buildEventOptions(context, component);
@@ -399,7 +414,7 @@
submitSuggest.addParameter(options);
script.append(submitSuggest.toScript()).append(";\n");
- return script.toString();
+ return "Richfaces.onAvailable('" + targetId + "',
function() {" + script.toString() + "});";
}
/**