Author: nbelaevski
Date: 2007-10-30 19:16:45 -0400 (Tue, 30 Oct 2007)
New Revision: 3627
Modified:
trunk/ui/tooltip/src/main/config/component/toolTip.xml
trunk/ui/tooltip/src/main/java/org/richfaces/component/UIToolTip.java
trunk/ui/tooltip/src/main/java/org/richfaces/renderkit/html/ToolTipRenderer.java
trunk/ui/tooltip/src/test/java/org/richfaces/renderkit/html/ToolTipRendererTest.java
Log:
http://jira.jboss.com/jira/browse/RF-1269
Modified: trunk/ui/tooltip/src/main/config/component/toolTip.xml
===================================================================
--- trunk/ui/tooltip/src/main/config/component/toolTip.xml 2007-10-30 20:39:59 UTC (rev
3626)
+++ trunk/ui/tooltip/src/main/config/component/toolTip.xml 2007-10-30 23:16:45 UTC (rev
3627)
@@ -80,6 +80,11 @@
<defaultvalue><![CDATA[""]]></defaultvalue>
</property>
+ <property>
+ <name>for</name>
+ <classname>java.lang.String</classname>
+ <description>Id of the target component.</description>
+ </property>
<property>
Modified: trunk/ui/tooltip/src/main/java/org/richfaces/component/UIToolTip.java
===================================================================
--- trunk/ui/tooltip/src/main/java/org/richfaces/component/UIToolTip.java 2007-10-30
20:39:59 UTC (rev 3626)
+++ trunk/ui/tooltip/src/main/java/org/richfaces/component/UIToolTip.java 2007-10-30
23:16:45 UTC (rev 3627)
@@ -105,7 +105,10 @@
public abstract void setZorder(int delay);
+ public abstract String getFor();
+ public abstract void setFor(String _for);
+
public String getUsedElementType(){
return getLayout().equals("block") ? "div" : "span";
}
Modified:
trunk/ui/tooltip/src/main/java/org/richfaces/renderkit/html/ToolTipRenderer.java
===================================================================
---
trunk/ui/tooltip/src/main/java/org/richfaces/renderkit/html/ToolTipRenderer.java 2007-10-30
20:39:59 UTC (rev 3626)
+++
trunk/ui/tooltip/src/main/java/org/richfaces/renderkit/html/ToolTipRenderer.java 2007-10-30
23:16:45 UTC (rev 3627)
@@ -135,18 +135,19 @@
}
- public Map buildEventOptions(FacesContext context, UIComponent component){
+ public Map buildEventOptions(FacesContext context, UIComponent component, String
targetId){
Map eventOptions = AjaxRendererUtils.buildEventOptions(context, component);
+ String jsVarName = "Richfaces.tooltips[\'" + targetId +
"\']";
//after element is subsituted in DOM tree, we have to re-create
//it's JS-reference, cause old one is already invalid
- String refreshTooltipInDOM = ";" + getJsVarName(context, component) +
".toolTip = $('" + component.getClientId(context) + "');" +
- ";" + getJsVarName(context, component) + ".toolTipContent =
$('" + component.getClientId(context) + "content');";
+ String refreshTooltipInDOM = ";" + jsVarName + ".toolTip = $('"
+ component.getClientId(context) + "');" +
+ ";" + jsVarName + ".toolTipContent = $('" +
component.getClientId(context) + "content');";
- String showNewToolTip = ";" + getJsVarName(context, component) +
".displayDiv();";
+ String showNewToolTip = ";" + jsVarName + ".displayDiv();";
// before element will be substituted in DOM tree, we need to hide toolTipe to
avoid blinking
- String fireBeforeUpdateDOM = ";" + getJsVarName(context, component) +
".toolTip.style.display = 'none';";
+ String fireBeforeUpdateDOM = ";" + jsVarName +
".toolTip.style.display = 'none';";
//enable ajaxSingle mode, i.e. we do not need to submit all form controls to get
tooltip content
@@ -204,10 +205,26 @@
writer.write(ret.toString());
}
+
+ private String getTargetId(FacesContext context, UIComponent component) {
+ UIToolTip toolTip = (UIToolTip) component;
+ String forValue = toolTip.getFor();
+
+ if (forValue != null && forValue.length() != 0) {
+ UIComponent targetComponent = component.findComponent(forValue);
+ if (targetComponent != null) {
+ return targetComponent.getClientId(context);
+ } else {
+ return forValue;
+ }
+ } else {
+ return component.getParent().getClientId(context);
+ }
+ }
public String constructJSVariable(FacesContext context, UIComponent component) {
UIToolTip toolTip = (UIToolTip)component;
- String parentClientId = toolTip.getParent().getClientId(context);
+ String targetClientId = getTargetId(context, component);
StringBuffer ret = new StringBuffer();
String comma = ",";
String quot = "\"";
@@ -229,10 +246,10 @@
function.addParameter(ref);
String ajaxFunc = function.toScript();
- Map ajaxOptions = buildEventOptions(context, toolTip);
+ Map ajaxOptions = buildEventOptions(context, toolTip, targetClientId);
ret.append("new ToolTip(" +
ScriptUtils.toScript(eventsMap)).append(comma).append(quot).append(
toolTip.getClientId(context)).append(quot).append(comma).
- append(quot).append(parentClientId).append(quot).append(comma).
+ append(quot).append(targetClientId).append(quot).append(comma).
append(quot).append(toolTip.getMode()).append(quot).append(comma).
append(toolTip.isDisabled()).append(comma).
append(quot).append(toolTip.getDirection()).append(quot).append(comma).
@@ -245,10 +262,6 @@
}
- private String getJsVarName(FacesContext context, UIComponent component){
- return "Richfaces.tooltips[\'" +
component.getParent().getClientId(context) + "\']";
- }
-
protected void doDecode(FacesContext context, UIComponent component) {
UIToolTip tooltip = (UIToolTip)component;
Modified:
trunk/ui/tooltip/src/test/java/org/richfaces/renderkit/html/ToolTipRendererTest.java
===================================================================
---
trunk/ui/tooltip/src/test/java/org/richfaces/renderkit/html/ToolTipRendererTest.java 2007-10-30
20:39:59 UTC (rev 3626)
+++
trunk/ui/tooltip/src/test/java/org/richfaces/renderkit/html/ToolTipRendererTest.java 2007-10-30
23:16:45 UTC (rev 3627)
@@ -1,13 +1,10 @@
package org.richfaces.renderkit.html;
-import java.io.IOException;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
-import javax.faces.component.UIComponent;
import javax.faces.component.html.HtmlOutputText;
-import javax.faces.context.FacesContext;
import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
import org.richfaces.component.UIToolTip;
@@ -104,7 +101,8 @@
public void testBuildEventOptions(){
- Map eventOptions = renderer.buildEventOptions(facesContext, toolTip);
+ Map eventOptions = renderer.buildEventOptions(facesContext, toolTip,
+ toolTip.getParent().getClientId(facesContext));
assertNotNull(eventOptions);
assertNotNull(eventOptions.get("oncomplete"));
}