dev@javaserverfaces.java.net

Seeking Review: Sending to EG as well: 49-getClientId from JS?

From: Ed Burns <Ed.Burns_at_Sun.COM>
Date: Thu, 06 Nov 2008 18:47:50 -0800

I'm sending this to the EG as well.

>>>>> On Mon, 03 Nov 2008 13:25:40 -0800, Jim Driscoll <Jim.Driscoll_at_Sun.COM> said:

JD> Isn't a gettable property of UINamingContainer, sadly.
JD> It requires a FacesContext.

JD> public String getClientId(FacesContext context) {

JD> So that
JD> #{compositeComponent.clientId}
JD> won't work, apparently. It throws an exception.

JD> Which is why Ryan said that we'll need method parameters to get
JD>

I've already checked this in. Can rollback if needed.


Issue: 49

Instead of having a js function that gives me the clientId, make it easy
to get the clientId from EL.


SECTION: Modified Files
----------------------------
M jsf-api/src/javax/faces/component/UIComponent.java

- Add this method:

    /**
     * <p class="changed_added_2_0">Enable EL to access the <code>clientId</code>
     * of a component. This is particularly useful in combination with the
     * <code>component</code> and <code>compositeComponent</code> implicit
     * objects. A default implementation is provided that simply calls
     * {_at_link FacesContext#getCurrentInstance} and then calls through to
     * {_at_link #getClientId(FacesContext)}.</p>
     *
     * @since 2.0
     */
    
    public String getClientId() {
        FacesContext context = FacesContext.getCurrentInstance();
        return getClientId(context);
    }

A jsf-ri/systest/web/composite
A jsf-ri/systest/web/composite/clientId01.xhtml
A jsf-ri/systest/web/resources/composite
A jsf-ri/systest/web/resources/composite/showClientId01.xhtml

tests.


SECTION: Diffs
----------------------------
Index: jsf-api/src/javax/faces/component/UIComponent.java
===================================================================
--- jsf-api/src/javax/faces/component/UIComponent.java (revision 5696)
+++ jsf-api/src/javax/faces/component/UIComponent.java (working copy)
@@ -408,6 +408,22 @@
     }
 
     // -------------------------------------------------------------- Properties
+
+ /**
+ * <p class="changed_added_2_0">Enable EL to access the <code>clientId</code>
+ * of a component. This is particularly useful in combination with the
+ * <code>component</code> and <code>compositeComponent</code> implicit
+ * objects. A default implementation is provided that simply calls
+ * {_at_link FacesContext#getCurrentInstance} and then calls through to
+ * {_at_link #getClientId(FacesContext)}.</p>
+ *
+ * @since 2.0
+ */
+
+ public String getClientId() {
+ FacesContext context = FacesContext.getCurrentInstance();
+ return getClientId(context);
+ }
 
 
     /**
Index: jsf-ri/systest/web/composite/clientId01.xhtml
===================================================================
--- jsf-ri/systest/web/composite/clientId01.xhtml (revision 0)
+++ jsf-ri/systest/web/composite/clientId01.xhtml (revision 0)
@@ -0,0 +1,99 @@
+<!--
+
+ DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+
+ Copyright 1997-2008 Sun Microsystems, Inc. All rights reserved.
+
+ The contents of this file are subject to the terms of either the GNU
+ General Public License Version 2 only ("GPL") or the Common Development
+ and Distribution License("CDDL") (collectively, the "License"). You
+ may not use this file except in compliance with the License. You can obtain
+ a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
+ or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
+ language governing permissions and limitations under the License.
+
+ When distributing the software, include this License Header Notice in each
+ file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
+ Sun designates this particular file as subject to the "Classpath" exception
+ as provided by Sun in the GPL Version 2 section of the License file that
+ accompanied this code. If applicable, add the following below the License
+ Header, with the fields enclosed by brackets [] replaced by your own
+ identifying information: "Portions Copyrighted [year]
+ [name of copyright owner]"
+
+ Contributor(s):
+
+ If you wish your version of this file to be governed by only the CDDL or
+ only the GPL Version 2, indicate your decision by adding "[Contributor]
+ elects to include this software in this distribution under the [CDDL or GPL
+ Version 2] license." If you don't indicate a single choice of license, a
+ recipient has the option to distribute your version of this file under
+ either the CDDL, the GPL Version 2 or to extend the choice of license to
+ its licensees as provided above. However, if you add GPL Version 2 code
+ and therefore, elected the GPL Version 2 license, then the option applies
+ only if the new code is made subject to such option by the copyright
+ holder.
+
+-->
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:h="http://java.sun.com/jsf/html"
+ xmlns:f="http://java.sun.com/jsf/core"
+ xmlns:ui="http://java.sun.com/jsf/facelets"
+ xmlns:ez="http://java.sun.com/jsf/composite/composite">
+<h:head>
+<title>clientId from EL</title>
+<style type="text/css">
+.grayBox { padding: 8px; margin: 10px 0; border: 1px solid #CCC; background-color: #f9f9f9; }
+</style>
+</h:head>
+
+<h:body>
+
+ <ui:debug hotkey="p" rendered="true"/>
+
+<h:form>
+
+<h1>Form with no componentId and no prependId </h1>
+
+ <p>No componentId on usage: <ez:showClientId01 /></p>
+
+ <p>Yes componentId on usage: <ez:showClientId01 id="componentId" /></p>
+
+</h:form>
+
+<h:form prependId="false">
+
+<h1>Form with no componentId and prependId </h1>
+
+ <p>No componentId on usage: <ez:showClientId01 /></p>
+
+ <p>Yes componentId on usage: <ez:showClientId01 id="componentId01" /></p>
+
+</h:form>
+
+<h:form id="form2">
+
+<h1>Form with a componentId and no prependId </h1>
+
+ <p>No componentId on usage: <ez:showClientId01 /></p>
+
+ <p>Yes componentId on usage: <ez:showClientId01 id="componentId" /></p>
+
+</h:form>
+
+<h:form prependId="false" id="form3">
+
+<h1>Form with a componentId and prependId </h1>
+
+ <p>No componentId on usage: <ez:showClientId01 /></p>
+
+ <p>Yes componentId on usage: <ez:showClientId01 id="componentId02" /></p>
+
+</h:form>
+
+
+
+</h:body>
+
+</html>
Index: jsf-ri/systest/web/resources/composite/showClientId01.xhtml
===================================================================
--- jsf-ri/systest/web/resources/composite/showClientId01.xhtml (revision 0)
+++ jsf-ri/systest/web/resources/composite/showClientId01.xhtml (revision 0)
@@ -0,0 +1,65 @@
+<!--
+
+ DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+
+ Copyright 1997-2008 Sun Microsystems, Inc. All rights reserved.
+
+ The contents of this file are subject to the terms of either the GNU
+ General Public License Version 2 only ("GPL") or the Common Development
+ and Distribution License("CDDL") (collectively, the "License"). You
+ may not use this file except in compliance with the License. You can obtain
+ a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
+ or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
+ language governing permissions and limitations under the License.
+
+ When distributing the software, include this License Header Notice in each
+ file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
+ Sun designates this particular file as subject to the "Classpath" exception
+ as provided by Sun in the GPL Version 2 section of the License file that
+ accompanied this code. If applicable, add the following below the License
+ Header, with the fields enclosed by brackets [] replaced by your own
+ identifying information: "Portions Copyrighted [year]
+ [name of copyright owner]"
+
+ Contributor(s):
+
+ If you wish your version of this file to be governed by only the CDDL or
+ only the GPL Version 2, indicate your decision by adding "[Contributor]
+ elects to include this software in this distribution under the [CDDL or GPL
+ Version 2] license." If you don't indicate a single choice of license, a
+ recipient has the option to distribute your version of this file under
+ either the CDDL, the GPL Version 2 or to extend the choice of license to
+ its licensees as provided above. However, if you add GPL Version 2 code
+ and therefore, elected the GPL Version 2 license, then the option applies
+ only if the new code is made subject to such option by the copyright
+ holder.
+
+-->
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:h="http://java.sun.com/jsf/html"
+ xmlns:f="http://java.sun.com/jsf/core"
+ xmlns:ui="http://java.sun.com/jsf/facelets"
+ xmlns:composite="http://java.sun.com/jsf/composite">
+<head>
+
+<title>Not present in rendered output</title>
+
+</head>
+
+<body>
+
+<composite:interface >
+
+</composite:interface>
+
+<composite:implementation>
+
+ <p class="grayBox">My clientId is #{compositeComponent.clientId}</p>
+
+
+</composite:implementation>
+
+</body>
+
+</html>


SECTION: New Files
----------------------------
SEE ATTACHMENTS

-- 
| ed.burns_at_sun.com  | office: 408 884 9519 OR x31640
| homepage:         | http://ridingthecrest.com/