You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lu...@apache.org on 2010/11/05 20:30:26 UTC
svn commit: r1031738 - in
/myfaces/commons/trunk/myfaces-commons-components/src/main: conf/META-INF/
java/org/apache/myfaces/commons/facelets/util/
java/org/apache/myfaces/commons/outputClientId/
Author: lu4242
Date: Fri Nov 5 19:30:25 2010
New Revision: 1031738
URL: http://svn.apache.org/viewvc?rev=1031738&view=rev
Log:
MFCOMMONS-20 Add mc:outputClientId component and Facelets EL function
Added:
myfaces/commons/trunk/myfaces-commons-components/src/main/java/org/apache/myfaces/commons/outputClientId/
myfaces/commons/trunk/myfaces-commons-components/src/main/java/org/apache/myfaces/commons/outputClientId/AbstractOutputClientId.java
Modified:
myfaces/commons/trunk/myfaces-commons-components/src/main/conf/META-INF/facelets-taglib-base.xml
myfaces/commons/trunk/myfaces-commons-components/src/main/java/org/apache/myfaces/commons/facelets/util/FaceletsFunctionLibrary.java
Modified: myfaces/commons/trunk/myfaces-commons-components/src/main/conf/META-INF/facelets-taglib-base.xml
URL: http://svn.apache.org/viewvc/myfaces/commons/trunk/myfaces-commons-components/src/main/conf/META-INF/facelets-taglib-base.xml?rev=1031738&r1=1031737&r2=1031738&view=diff
==============================================================================
--- myfaces/commons/trunk/myfaces-commons-components/src/main/conf/META-INF/facelets-taglib-base.xml (original)
+++ myfaces/commons/trunk/myfaces-commons-components/src/main/conf/META-INF/facelets-taglib-base.xml Fri Nov 5 19:30:25 2010
@@ -27,4 +27,10 @@
<function-signature>javax.faces.component.UIComponent findComponent(java.lang.String)</function-signature>
</function>
+ <function>
+ <function-name>outputClientId</function-name>
+ <function-class>org.apache.myfaces.commons.facelets.util.FaceletsFunctionLibrary</function-class>
+ <function-signature>java.lang.String outputClientId(java.lang.String)</function-signature>
+ </function>
+
</facelet-taglib>
\ No newline at end of file
Modified: myfaces/commons/trunk/myfaces-commons-components/src/main/java/org/apache/myfaces/commons/facelets/util/FaceletsFunctionLibrary.java
URL: http://svn.apache.org/viewvc/myfaces/commons/trunk/myfaces-commons-components/src/main/java/org/apache/myfaces/commons/facelets/util/FaceletsFunctionLibrary.java?rev=1031738&r1=1031737&r2=1031738&view=diff
==============================================================================
--- myfaces/commons/trunk/myfaces-commons-components/src/main/java/org/apache/myfaces/commons/facelets/util/FaceletsFunctionLibrary.java (original)
+++ myfaces/commons/trunk/myfaces-commons-components/src/main/java/org/apache/myfaces/commons/facelets/util/FaceletsFunctionLibrary.java Fri Nov 5 19:30:25 2010
@@ -34,4 +34,10 @@ public final class FaceletsFunctionLibra
return FacesContext.getCurrentInstance().
getViewRoot().findComponent(expr);
}
+
+ public static String outputClientId(String expr)
+ {
+ FacesContext ctx = FacesContext.getCurrentInstance();
+ return ctx.getViewRoot().findComponent(expr).getClientId(ctx);
+ }
}
Added: myfaces/commons/trunk/myfaces-commons-components/src/main/java/org/apache/myfaces/commons/outputClientId/AbstractOutputClientId.java
URL: http://svn.apache.org/viewvc/myfaces/commons/trunk/myfaces-commons-components/src/main/java/org/apache/myfaces/commons/outputClientId/AbstractOutputClientId.java?rev=1031738&view=auto
==============================================================================
--- myfaces/commons/trunk/myfaces-commons-components/src/main/java/org/apache/myfaces/commons/outputClientId/AbstractOutputClientId.java (added)
+++ myfaces/commons/trunk/myfaces-commons-components/src/main/java/org/apache/myfaces/commons/outputClientId/AbstractOutputClientId.java Fri Nov 5 19:30:25 2010
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.commons.outputClientId;
+
+import java.io.IOException;
+
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIComponentBase;
+import javax.faces.context.FacesContext;
+
+import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFComponent;
+import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFProperty;
+
+/**
+ * Output the clientId of a component specified by for property.
+ *
+ * @author Leonardo Uribe
+ * @since 1.0.1
+ */
+@JSFComponent(
+ name = "mc:outputClientId",
+ clazz = "org.apache.myfaces.commons.outputClientId.OutputClientId",
+ tagClass = "org.apache.myfaces.commons.outputClientId.OutputClientIdTag")
+public abstract class AbstractOutputClientId extends UIComponentBase
+{
+ public static final String COMPONENT_FAMILY = "javax.faces.Output";
+ public static final String COMPONENT_TYPE = "org.apache.myfaces.commons.OutputClientId";
+
+ /**
+ * The ID of the component that should be rendered.
+ *
+ * @return
+ */
+ @JSFProperty
+ public abstract String getFor();
+
+ @Override
+ public void encodeBegin(FacesContext context) throws IOException
+ {
+ super.encodeBegin(context);
+
+ String forId = getFor();
+ UIComponent referencedComponent = null;
+
+ if (forId == null)
+ {
+ referencedComponent = getParent();
+ }
+ else
+ {
+ referencedComponent = this.findComponent(forId);
+ }
+
+ if (referencedComponent == null)
+ {
+ throw new IllegalStateException("No component found for id : "
+ + forId);
+ }
+
+ context.getResponseWriter().write(
+ referencedComponent.getClientId(context));
+ }
+}