Author: nbelaevski
Date: 2010-05-23 15:45:36 -0400 (Sun, 23 May 2010)
New Revision: 17194
Modified:
root/ui/misc/trunk/ui/src/main/java/org/richfaces/function/RichFunction.java
Log:
https://jira.jboss.org/browse/RF-7983
Modified: root/ui/misc/trunk/ui/src/main/java/org/richfaces/function/RichFunction.java
===================================================================
---
root/ui/misc/trunk/ui/src/main/java/org/richfaces/function/RichFunction.java 2010-05-23
19:40:45 UTC (rev 17193)
+++
root/ui/misc/trunk/ui/src/main/java/org/richfaces/function/RichFunction.java 2010-05-23
19:45:36 UTC (rev 17194)
@@ -24,12 +24,12 @@
import java.util.Set;
import javax.faces.component.UIComponent;
-import javax.faces.component.UIViewRoot;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import org.ajax4jsf.renderkit.AjaxRendererUtils;
import org.ajax4jsf.renderkit.RendererUtils;
+import org.richfaces.cdk.annotations.Function;
/**
* Created 20.03.2008
@@ -37,15 +37,22 @@
* @since 3.2
*/
-public class RichFunction {
+public final class RichFunction {
+ private RichFunction() {
+ //utility class constructor
+ }
+
private static UIComponent findComponent(FacesContext context, String id) {
if (id != null) {
if (context != null) {
- UIViewRoot root = context.getViewRoot();
+ UIComponent contextComponent = UIComponent.getCurrentComponent(context);
+ if (contextComponent == null) {
+ contextComponent = context.getViewRoot();
+ }
- if (root != null) {
- UIComponent component = RendererUtils.getInstance().findComponentFor(root, id);
+ if (contextComponent != null) {
+ UIComponent component =
RendererUtils.getInstance().findComponentFor(contextComponent, id);
if (component != null) {
return component;
@@ -57,21 +64,24 @@
return null;
}
+ @Function
public static String clientId(String id) {
FacesContext context = FacesContext.getCurrentInstance();
UIComponent component = findComponent(context, id);
return component != null ? component.getClientId(context) : null;
}
+ @Function
public static String component(String id) {
String element = element(id);
if (element != null) {
- return element + ".component";
+ return "jQuery.RichFaces.$(" + clientId(id) + ")";
}
return null;
}
+ @Function
public static String element(String id) {
String clientId = clientId(id);
if (clientId != null) {
@@ -81,6 +91,7 @@
return null;
}
+ @Function
public static UIComponent findComponent(String id) {
return findComponent(FacesContext.getCurrentInstance(), id);
}
@@ -90,7 +101,9 @@
* @param rolesObject
* @return
*/
+ @Function
public static boolean isUserInRole(Object rolesObject) {
+ //TODO nick - AjaxRendererUtils split text by commas and whitespace, what is the
right variant?
Set<String> rolesSet = AjaxRendererUtils.asSet(rolesObject);
if (rolesSet != null) {
FacesContext facesContext = FacesContext.getCurrentInstance();