You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by mk...@apache.org on 2005/11/28 23:15:19 UTC
svn commit: r349524 - in /myfaces: examples/trunk/sandbox/
forrest/trunk/content/xdocs/ forrest/trunk/content/xdocs/sandbox/
sandbox/trunk/conf/ sandbox/trunk/src/java/org/apache/myfaces/custom/focus/
Author: mkienenb
Date: Mon Nov 28 14:15:03 2005
New Revision: 349524
URL: http://svn.apache.org/viewcvs?rev=349524&view=rev
Log:
Added Focus sandbox component. MYFACES-862. Thanks, Rogerio.
Added:
myfaces/examples/trunk/sandbox/focus.jsp (with props)
myfaces/forrest/trunk/content/xdocs/sandbox/focus.xml (with props)
myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/focus/HtmlFocus.java (with props)
myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/focus/HtmlFocusRenderer.java (with props)
myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/focus/HtmlFocusTag.java (with props)
Modified:
myfaces/examples/trunk/sandbox/home.jsp
myfaces/forrest/trunk/content/xdocs/site.xml
myfaces/sandbox/trunk/conf/faces-config.xml
Added: myfaces/examples/trunk/sandbox/focus.jsp
URL: http://svn.apache.org/viewcvs/myfaces/examples/trunk/sandbox/focus.jsp?rev=349524&view=auto
==============================================================================
--- myfaces/examples/trunk/sandbox/focus.jsp (added)
+++ myfaces/examples/trunk/sandbox/focus.jsp Mon Nov 28 14:15:03 2005
@@ -0,0 +1,60 @@
+<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
+<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
+<%@ taglib uri="http://myfaces.apache.org/tomahawk" prefix="t"%>
+<%@ taglib uri="http://myfaces.apache.org/sandbox" prefix="s"%>
+<%@ page contentType="text/html;charset=iso-8859-1"%>
+<html>
+ <head>
+ <title>Test</title>
+ </head>
+ <body>
+ setting focus on input2<br/>
+ text<br/>
+ text<br/>
+ text<br/>
+ text<br/>
+ text<br/>
+ text<br/>
+ text<br/>
+ text<br/>
+ text<br/>
+ text<br/>
+ text<br/>
+ text<br/>
+ text<br/>
+ text<br/>
+ text<br/>
+ text<br/>
+ text<br/>
+ text<br/>
+ text<br/>
+ text<br/>
+ text<br/>
+ text<br/>
+ text<br/>
+ text<br/>
+ text<br/>
+ text<br/>
+ text<br/>
+ text<br/>
+ text<br/>
+ text<br/>
+ text<br/>
+ text<br/>
+ text<br/>
+ text<br/>
+ text<br/>
+ <f:view>
+ <h:form id="formTest">
+ <h:outputLabel for="input1" value="Input1: "/>
+ <h:inputText id="input1"/>
+ <h:outputLabel for="input2" value="Input2: "/>
+ <h:inputText id="input2"/>
+ <h:outputLabel for="input3" value="Input3: "/>
+ <h:inputText id="input3"/>
+ <s:focus id="focus" for="input2" />
+ </h:form>
+ </f:view>
+ </body>
+</html>
+
Propchange: myfaces/examples/trunk/sandbox/focus.jsp
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/examples/trunk/sandbox/focus.jsp
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Modified: myfaces/examples/trunk/sandbox/home.jsp
URL: http://svn.apache.org/viewcvs/myfaces/examples/trunk/sandbox/home.jsp?rev=349524&r1=349523&r2=349524&view=diff
==============================================================================
--- myfaces/examples/trunk/sandbox/home.jsp (original)
+++ myfaces/examples/trunk/sandbox/home.jsp Mon Nov 28 14:15:03 2005
@@ -30,6 +30,7 @@
<h:commandLink action="go_scope_shop"><f:verbatim>Scope - saveState without serialisation</f:verbatim></h:commandLink>
<h:outputLink value="picklist.jsf"><f:verbatim>selectManyPicklist - a picklist</f:verbatim></h:outputLink>
<h:outputLink value="dateTimeConverter.jsf"><f:verbatim>DateTimeConverter - a datetime converter that uses system timezone as default</f:verbatim></h:outputLink>
+ <h:outputLink value="focus.jsf"><f:verbatim>Focus - a component to set a target component as the focus on page load.</f:verbatim></h:outputLink>
</h:panelGrid>
</f:view>
Added: myfaces/forrest/trunk/content/xdocs/sandbox/focus.xml
URL: http://svn.apache.org/viewcvs/myfaces/forrest/trunk/content/xdocs/sandbox/focus.xml?rev=349524&view=auto
==============================================================================
--- myfaces/forrest/trunk/content/xdocs/sandbox/focus.xml (added)
+++ myfaces/forrest/trunk/content/xdocs/sandbox/focus.xml Mon Nov 28 14:15:03 2005
@@ -0,0 +1,89 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE document PUBLIC "-//APACHE//DTD Documentation V1.2//EN" "document-v12.dtd">
+
+<!--
+This is a standard template meant to be used for the documentation of all custom
+components.
+-->
+<document>
+ <!-- component name -->
+ <header>
+ <title>Focus</title>
+ <subtitle><s:focus></subtitle>
+ </header>
+ <body>
+ <!-- Description -->
+ <section>
+ <title>Description</title>
+ <p>
+ This component provides a way to control which component receives focus when the page loads.
+ </p>
+ </section>
+ <!-- screen shot -->
+ <section>
+ <title>Screen Shot</title>
+ <p>Not Available</p> <!-- replace with either a figure or Not Available -->
+ <!--
+ <figure src="jscookmenu.png" alt="jscookmenu"/>
+ -->
+ </section>
+ <!-- API -->
+ <section>
+ <title>API</title>
+ <table>
+ <tr>
+ <td>component-family</td>
+ <td>javax.faces.Output</td>
+ </tr>
+ <tr>
+ <td>renderer-type</td>
+ <td>org.apache.myfaces.Focus</td>
+ </tr>
+ <tr>
+ <td>component-class</td>
+ <td>org.apache.myfaces.custom.focus.HtmlFocus</td>
+ </tr>
+ <tr>
+ <td>renderer-class</td>
+ <td>org.apache.myfaces.custom.focus.HtmlFocusRenderer</td>
+ </tr>
+ <tr>
+ <td>tag-class</td>
+ <td>org.apache.myfaces.custom.focus.HtmlFocusTag</td>
+ </tr>
+ </table>
+ </section>
+
+ <!-- Usage -->
+ <section>
+ <title>Usage</title>
+ <source><h:inputText id="textfield" value="#{bean.value}" />
+<s:focus id="focus" for="textfield" /></source>
+ <source><s:focus id="focus" for="#{bean.focusedComponentId}" /></source>
+ </section>
+
+ <!-- Syntax -->
+ <section>
+ <title>Syntax</title>
+ <note label="<s:focus>">
+ <code>for="reference to UIComponent"</code><br/>
+ </note>
+ </section>
+
+ <!-- Additional Information -->
+ <section>
+ <title>Additional Information</title>
+ <p>The best place to use this component is right before the </f:form> tag.</p>
+ </section>
+
+ </body>
+ <footer>
+ <legal>Java, J2EE, and JCP are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries.<br />
+ © 2004 - 2005, Apache Software Foundation
+ </legal>
+ </footer>
+
+</document>
+
+
+
Propchange: myfaces/forrest/trunk/content/xdocs/sandbox/focus.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/forrest/trunk/content/xdocs/sandbox/focus.xml
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Modified: myfaces/forrest/trunk/content/xdocs/site.xml
URL: http://svn.apache.org/viewcvs/myfaces/forrest/trunk/content/xdocs/site.xml?rev=349524&r1=349523&r2=349524&view=diff
==============================================================================
--- myfaces/forrest/trunk/content/xdocs/site.xml (original)
+++ myfaces/forrest/trunk/content/xdocs/site.xml Mon Nov 28 14:15:03 2005
@@ -159,6 +159,7 @@
<autoUpdateDataTable label="Auto Update DataTable" href="autoUpdateDataTable.html"/>
<inputSuggest label="Input Suggest" href="inputSuggest.html"/>
<schedule label="Schedule" href="schedule.html"/>
+ <form label="Focus" href="focus.html"/>
<form label="Form" href="form.html"/>
<picklist label="Picklist" href="selectManyPicklist.html"/>
</sandbox-components>
Modified: myfaces/sandbox/trunk/conf/faces-config.xml
URL: http://svn.apache.org/viewcvs/myfaces/sandbox/trunk/conf/faces-config.xml?rev=349524&r1=349523&r2=349524&view=diff
==============================================================================
--- myfaces/sandbox/trunk/conf/faces-config.xml (original)
+++ myfaces/sandbox/trunk/conf/faces-config.xml Mon Nov 28 14:15:03 2005
@@ -69,6 +69,11 @@
<component-class>org.apache.myfaces.custom.accordion.HtmlAccordionPanel</component-class>
</component>
+ <component>
+ <component-type>org.apache.myfaces.Focus</component-type>
+ <component-class>org.apache.myfaces.custom.focus.HtmlFocus</component-class>
+ </component>
+
<component>
<component-type>org.apache.myfaces.HtmlForm</component-type>
<component-class>org.apache.myfaces.custom.form.HtmlForm</component-class>
@@ -179,12 +184,17 @@
<renderer-class>org.apache.myfaces.custom.autoupdatedatatable.AutoUpdateDataTableRenderer</renderer-class>
</renderer>
- <renderer>
- <component-family>javax.faces.Panel</component-family>
- <renderer-type>org.apache.myfaces.AccordionPanel</renderer-type>
- <renderer-class>org.apache.myfaces.custom.accordion.HtmlAccordionPanelRenderer</renderer-class>
- </renderer>
+ <renderer>
+ <component-family>javax.faces.Panel</component-family>
+ <renderer-type>org.apache.myfaces.AccordionPanel</renderer-type>
+ <renderer-class>org.apache.myfaces.custom.accordion.HtmlAccordionPanelRenderer</renderer-class>
+ </renderer>
+ <renderer>
+ <component-family>javax.faces.Output</component-family>
+ <renderer-type>org.apache.myfaces.Focus</renderer-type>
+ <renderer-class>org.apache.myfaces.custom.focus.HtmlFocusRenderer</renderer-class>
+ </renderer>
<renderer>
<component-family>javax.faces.Form</component-family>
Added: myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/focus/HtmlFocus.java
URL: http://svn.apache.org/viewcvs/myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/focus/HtmlFocus.java?rev=349524&view=auto
==============================================================================
--- myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/focus/HtmlFocus.java (added)
+++ myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/focus/HtmlFocus.java Mon Nov 28 14:15:03 2005
@@ -0,0 +1,95 @@
+/**
+ * Copyright 2004-2005 The Apache Software Foundation.
+ *
+ * Licensed 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.custom.focus;
+
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIComponentBase;
+import javax.faces.context.FacesContext;
+import javax.faces.el.ValueBinding;
+
+/**
+ * @author Rogerio Pereira Araujo (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+public class HtmlFocus extends UIComponentBase
+{
+ public static final String COMPONENT_TYPE = "org.apache.myfaces.Focus";
+ public static final String DEFAULT_RENDERER_TYPE = "org.apache.myfaces.Focus";
+ public static final String COMPONENT_FAMILY = "javax.faces.Output";
+
+ private String _for = null;
+
+ public String getFamily()
+ {
+ return COMPONENT_FAMILY;
+ }
+
+ public void setFor(String forValue)
+ {
+ _for = forValue;
+ }
+
+ public String getFor()
+ {
+ if (_for != null)
+ return _for;
+ ValueBinding vb = getValueBinding("for");
+ return vb != null ? (String) vb.getValue(getFacesContext()) : null;
+ }
+
+
+ protected UIComponent findUIComponent()
+ {
+ String forStr = getFor();
+
+ // It's unclear to me whether the following is necessary or useful.
+ if(forStr == null)
+ {
+ forStr = (String) this.getAttributes().get("for");
+ }
+
+ if (forStr == null)
+ {
+ throw new IllegalArgumentException("focus@for must be specified");
+ }
+
+ UIComponent forComp = findComponent(forStr);
+ if (forComp == null)
+ {
+ throw new IllegalArgumentException(
+ "could not find UIComponent referenced by attribute focus@for = '"
+ + forStr + "'");
+ }
+ return forComp;
+ }
+
+ public Object saveState(FacesContext context)
+ {
+ Object values[] = new Object[2];
+ values[0] = super.saveState(context);
+ values[1] = _for;
+ return values;
+ }
+
+ public void restoreState(FacesContext context, Object state)
+ {
+ Object values[] = (Object[]) state;
+ super.restoreState(context, values[0]);
+ _for = (String) values[1];
+ }
+
+}
+
\ No newline at end of file
Propchange: myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/focus/HtmlFocus.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/focus/HtmlFocus.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/focus/HtmlFocusRenderer.java
URL: http://svn.apache.org/viewcvs/myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/focus/HtmlFocusRenderer.java?rev=349524&view=auto
==============================================================================
--- myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/focus/HtmlFocusRenderer.java (added)
+++ myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/focus/HtmlFocusRenderer.java Mon Nov 28 14:15:03 2005
@@ -0,0 +1,58 @@
+/**
+ * Copyright 2004-2005 The Apache Software Foundation.
+ *
+ * Licensed 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.custom.focus;
+
+import java.io.IOException;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+import javax.faces.render.Renderer;
+
+import org.apache.myfaces.renderkit.RendererUtils;
+import org.apache.myfaces.renderkit.html.HTML;
+
+/**
+ * @author Rogerio Pereira Araujo (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+public class HtmlFocusRenderer extends Renderer
+{
+
+ public void encodeEnd(FacesContext facesContext, UIComponent uiComponent)
+ throws IOException
+ {
+ RendererUtils.checkParamValidity(facesContext, uiComponent,
+ HtmlFocus.class);
+
+ HtmlFocus focus = (HtmlFocus) uiComponent;
+
+ UIComponent targetComponent = focus.findUIComponent();
+
+ if(targetComponent != null)
+ {
+ String clientId = targetComponent.getClientId(facesContext);
+
+ ResponseWriter writer = facesContext.getResponseWriter();
+
+ writer.startElement(HTML.SCRIPT_ELEM, uiComponent);
+ writer.writeAttribute(HTML.SCRIPT_TYPE_ATTR, HTML.SCRIPT_TYPE_TEXT_JAVASCRIPT, null);
+ writer.writeText("document.getElementById('" + clientId + "').focus()", null);
+ writer.endElement(HTML.SCRIPT_ELEM);
+ }
+ }
+
+}
Propchange: myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/focus/HtmlFocusRenderer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/focus/HtmlFocusRenderer.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/focus/HtmlFocusTag.java
URL: http://svn.apache.org/viewcvs/myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/focus/HtmlFocusTag.java?rev=349524&view=auto
==============================================================================
--- myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/focus/HtmlFocusTag.java (added)
+++ myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/focus/HtmlFocusTag.java Mon Nov 28 14:15:03 2005
@@ -0,0 +1,63 @@
+/**
+ * Copyright 2004-2005 The Apache Software Foundation.
+ *
+ * Licensed 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.custom.focus;
+
+import javax.faces.component.UIComponent;
+
+import org.apache.myfaces.taglib.UIComponentTagBase;
+
+/**
+ * @author Rogerio Pereira Araujo (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+public class HtmlFocusTag extends UIComponentTagBase
+{
+ private static final String FOR_ATTR = "for";
+
+ private String _for;
+
+ public void release() {
+
+ super.release();
+ _for = null;
+
+ }
+
+ public String getComponentType() {
+
+ return HtmlFocus.COMPONENT_TYPE;
+
+ }
+
+ public String getRendererType() {
+
+ return HtmlFocus.DEFAULT_RENDERER_TYPE;
+
+ }
+
+ protected void setProperties(UIComponent component) {
+
+ super.setProperties(component);
+
+ setStringProperty(component, FOR_ATTR, _for);
+ }
+
+ public void setFor(String aFor)
+ {
+ _for = aFor;
+ }
+}
+
\ No newline at end of file
Propchange: myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/focus/HtmlFocusTag.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/focus/HtmlFocusTag.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL