Author: maksimkaszynski
Date: 2007-10-15 13:11:22 -0400 (Mon, 15 Oct 2007)
New Revision: 3381
Modified:
branches/3.1.x/framework/impl/src/main/java/org/richfaces/component/util/HtmlUtil.java
branches/3.1.x/framework/test/src/test/java/org/richfaces/component/util/HtmlUtilTest.java
branches/3.1.x/ui/jQuery/src/main/java/org/richfaces/renderkit/JQueryRendererBase.java
branches/3.1.x/ui/jQuery/src/main/templates/jQuery.jspx
Log:
http://jira.jboss.com/jira/browse/RF-1096
merged from trunk
Modified:
branches/3.1.x/framework/impl/src/main/java/org/richfaces/component/util/HtmlUtil.java
===================================================================
---
branches/3.1.x/framework/impl/src/main/java/org/richfaces/component/util/HtmlUtil.java 2007-10-15
17:11:02 UTC (rev 3380)
+++
branches/3.1.x/framework/impl/src/main/java/org/richfaces/component/util/HtmlUtil.java 2007-10-15
17:11:22 UTC (rev 3381)
@@ -21,11 +21,16 @@
package org.richfaces.component.util;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+
import org.ajax4jsf.util.HtmlDimensions;
/**
- * @author Nick Belaevski - nbelaevski(a)exadel.com
- * created 09.02.2007
+ * @author Nick Belaevski - nbelaevski(a)exadel.com created 09.02.2007
*
*/
public class HtmlUtil {
@@ -40,12 +45,39 @@
return sizeDeclaration;
}
-
+
public static String addToSize(String declaration, String delta) {
Double doubleDelta = HtmlDimensions.decode(delta);
Double decoded = HtmlDimensions.decode(declaration);
-
- return HtmlDimensions.formatPx(
- new Double(decoded.doubleValue() + doubleDelta.doubleValue()));
+
+ return HtmlDimensions.formatPx(new Double(decoded.doubleValue()
+ + doubleDelta.doubleValue()));
}
+
+ public static final Pattern idSelectorPattern = Pattern
+ .compile("#((:|_|[a-z,A-Z])[a-z,A-Z,0-9,_,-,:]+)");
+
+ public static String expandIdSelector(String selector,
+ UIComponent component, FacesContext context) {
+ Matcher matcher = idSelectorPattern.matcher(selector);
+ StringBuffer sb = new StringBuffer();
+
+ while (matcher.find()) {
+ if (matcher.group(1).indexOf("::") == -1) {
+ // make new id selector here using matcher.group(1)
+
+ UIComponent target = component.findComponent(matcher.group(1));
+
+ if (target != null) {
+ matcher.appendReplacement(sb, "#"
+ + target.getClientId(context));
+ }
+ }
+ }
+ matcher.appendTail(sb);
+ String result = sb.toString();
+ if (result.length() == 0)
+ result = selector;
+ return sb.toString();
+ }
}
Modified:
branches/3.1.x/framework/test/src/test/java/org/richfaces/component/util/HtmlUtilTest.java
===================================================================
---
branches/3.1.x/framework/test/src/test/java/org/richfaces/component/util/HtmlUtilTest.java 2007-10-15
17:11:02 UTC (rev 3380)
+++
branches/3.1.x/framework/test/src/test/java/org/richfaces/component/util/HtmlUtilTest.java 2007-10-15
17:11:22 UTC (rev 3381)
@@ -21,6 +21,14 @@
package org.richfaces.component.util;
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIComponentBase;
+import javax.faces.component.UIInput;
+import javax.faces.component.html.HtmlForm;
+import javax.faces.context.FacesContext;
+
+import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
+
import junit.framework.TestCase;
/**
@@ -29,6 +37,19 @@
*
*/
public class HtmlUtilTest extends TestCase {
+
+ public HtmlUtilTest(String name) {
+ super(name);
+ }
+
+ public void setUp() throws Exception {
+ super.setUp();
+ }
+
+ public void tearDown() throws Exception {
+ super.tearDown();
+ }
+
public void testQualifySize() throws Exception {
assertEquals("", HtmlUtil.qualifySize(""));
@@ -48,4 +69,48 @@
assertEquals("120px", HtmlUtil.addToSize("100", "20"));
assertEquals("120px", HtmlUtil.addToSize("100px",
"20px"));
}
+
+ public void testExpandIdSelector() {
+ String selector = ".class_form+#:Test .class2 #_1aaaa:";
+
+ UIComponent component = new UIComponentBase() {
+ public String getFamily() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+ public UIComponent findComponent(String expr) {
+ if (":Test".equals(expr)) {
+ return new UIComponentBase() {
+ public String getClientId(FacesContext context) {
+ return "component1";
+ }
+ public String getFamily() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+ };
+ } else if ("_1aaaa:".equals(expr)) {
+ return new UIComponentBase() {
+ public String getClientId(FacesContext context) {
+ return "component2";
+ }
+ public String getFamily() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+ };
+ }
+
+ return null;
+ }
+ };
+
+ String string =
+ HtmlUtil.expandIdSelector(selector, component, null);
+
+ assertEquals(".class_form+#component1 .class2 #component2", string);
+
+ String s = ".class_form+.component1 .class2 #1component2";
+ assertEquals(s, HtmlUtil.expandIdSelector(s, component, null));
+ }
}
Modified:
branches/3.1.x/ui/jQuery/src/main/java/org/richfaces/renderkit/JQueryRendererBase.java
===================================================================
---
branches/3.1.x/ui/jQuery/src/main/java/org/richfaces/renderkit/JQueryRendererBase.java 2007-10-15
17:11:02 UTC (rev 3380)
+++
branches/3.1.x/ui/jQuery/src/main/java/org/richfaces/renderkit/JQueryRendererBase.java 2007-10-15
17:11:22 UTC (rev 3381)
@@ -10,6 +10,7 @@
import org.ajax4jsf.renderkit.ComponentVariables;
import org.ajax4jsf.renderkit.HeaderResourcesRendererBase;
import org.richfaces.component.UIJQuery;
+import org.richfaces.component.util.HtmlUtil;
public class JQueryRendererBase extends HeaderResourcesRendererBase {
@@ -47,8 +48,8 @@
}
}
- protected String replaceClientIds(String selector) {
- return selector;
+ protected String replaceClientIds(FacesContext context, UIComponent component, String
selector) {
+ return HtmlUtil.expandIdSelector(selector, component, context);
}
Modified: branches/3.1.x/ui/jQuery/src/main/templates/jQuery.jspx
===================================================================
--- branches/3.1.x/ui/jQuery/src/main/templates/jQuery.jspx 2007-10-15 17:11:02 UTC (rev
3380)
+++ branches/3.1.x/ui/jQuery/src/main/templates/jQuery.jspx 2007-10-15 17:11:22 UTC (rev
3381)
@@ -26,7 +26,7 @@
String selector = (String) variables.getVariable("selector");
checkValidity(clientId, name, timing, query);
- variables.setVariable("selector", replaceClientIds(selector));
+ variables.setVariable("selector", replaceClientIds(context, component,
selector));
]]>
</jsp:scriptlet>