You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by mm...@apache.org on 2005/06/12 14:41:17 UTC

svn commit: r190263 - in /myfaces/trunk/src/components/org/apache/myfaces/custom/inputTextHelp: ./ HtmlInputTextHelp.java HtmlInputTextHelp.xml HtmlInputTextHelpTag.java HtmlTextHelpRenderer.java resource/ resource/inputTextHelp.js

Author: mmarinschek
Date: Sun Jun 12 05:41:16 2005
New Revision: 190263

URL: http://svn.apache.org/viewcvs?rev=190263&view=rev
Log: (empty)

Added:
    myfaces/trunk/src/components/org/apache/myfaces/custom/inputTextHelp/
    myfaces/trunk/src/components/org/apache/myfaces/custom/inputTextHelp/HtmlInputTextHelp.java
    myfaces/trunk/src/components/org/apache/myfaces/custom/inputTextHelp/HtmlInputTextHelp.xml
    myfaces/trunk/src/components/org/apache/myfaces/custom/inputTextHelp/HtmlInputTextHelpTag.java
    myfaces/trunk/src/components/org/apache/myfaces/custom/inputTextHelp/HtmlTextHelpRenderer.java
    myfaces/trunk/src/components/org/apache/myfaces/custom/inputTextHelp/resource/
    myfaces/trunk/src/components/org/apache/myfaces/custom/inputTextHelp/resource/inputTextHelp.js

Added: myfaces/trunk/src/components/org/apache/myfaces/custom/inputTextHelp/HtmlInputTextHelp.java
URL: http://svn.apache.org/viewcvs/myfaces/trunk/src/components/org/apache/myfaces/custom/inputTextHelp/HtmlInputTextHelp.java?rev=190263&view=auto
==============================================================================
--- myfaces/trunk/src/components/org/apache/myfaces/custom/inputTextHelp/HtmlInputTextHelp.java (added)
+++ myfaces/trunk/src/components/org/apache/myfaces/custom/inputTextHelp/HtmlInputTextHelp.java Sun Jun 12 05:41:16 2005
@@ -0,0 +1,78 @@
+package org.apache.myfaces.custom.inputTextHelp;
+
+import org.apache.myfaces.component.html.util.HtmlComponentUtils;
+import org.apache.myfaces.component.html.ext.HtmlInputText;
+
+import javax.faces.el.ValueBinding;
+import javax.faces.context.FacesContext;
+
+/**
+ * @author Thomas Obereder
+ * @version $Date: 2005-07-02 15:32:34 +01:00 (Thu, 09 Jun 2005)
+ */
+public class HtmlInputTextHelp extends HtmlInputText
+{
+    public static final String JS_FUNCTION_SELECT_TEXT = "selectText";
+    public static final String JS_FUNCTION_RESET_HELP = "resetHelpValue";
+    public static final String COMPONENT_TYPE = "org.apache.myfaces.HtmlInputTextHelp";
+
+    private String _helpText = null;
+    private Boolean _selectText = null;
+
+    public String getClientId(FacesContext context)
+    {
+        String clientId = HtmlComponentUtils.getClientId(this, getRenderer(context), context);
+        if (clientId == null)
+        {
+            clientId = super.getClientId(context);
+        }
+
+        return clientId;
+    }
+
+    public HtmlInputTextHelp()
+    {
+    }
+
+    public String getHelpText()
+    {
+        if(_helpText != null) return _helpText;
+        ValueBinding vb = getValueBinding("helpText");
+        return vb != null ? (String)vb.getValue(getFacesContext()) : null;
+    }
+
+    public void setHelpText(String helpText)
+    {
+        _helpText = helpText;
+    }
+
+    public boolean isSelectText()
+    {
+        if (_selectText != null) return _selectText.booleanValue();
+        ValueBinding vb = getValueBinding("selectText");
+        Boolean v = vb != null ? (Boolean)vb.getValue(getFacesContext()) : null;
+        return v != null ? v.booleanValue() : false;
+    }
+
+    public void setSelectText(boolean selectText)
+    {
+        _selectText = Boolean.valueOf(selectText);
+    }
+
+    public Object saveState(FacesContext context)
+    {
+        Object[] state = new Object[4];
+        state[0] = super.saveState(context);
+        state[1] = _helpText;
+        state[2] = _selectText;
+        return state;
+    }
+
+    public void restoreState(FacesContext context, Object state)
+    {
+        Object values[] = (Object[])state;
+        super.restoreState(context, values[0]);
+        _helpText = (String)values[1];
+        _selectText = (Boolean)values[2];
+    }
+}

Added: myfaces/trunk/src/components/org/apache/myfaces/custom/inputTextHelp/HtmlInputTextHelp.xml
URL: http://svn.apache.org/viewcvs/myfaces/trunk/src/components/org/apache/myfaces/custom/inputTextHelp/HtmlInputTextHelp.xml?rev=190263&view=auto
==============================================================================
--- myfaces/trunk/src/components/org/apache/myfaces/custom/inputTextHelp/HtmlInputTextHelp.xml (added)
+++ myfaces/trunk/src/components/org/apache/myfaces/custom/inputTextHelp/HtmlInputTextHelp.xml Sun Jun 12 05:41:16 2005
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="ISO-8859-1" ?>
+<!DOCTYPE component PUBLIC
+  "-//MyFaces//DTD MyFaces component def 1.0//EN"
+  "http://myfaces.apache.org/dtd/Component.dtd">
+<component generateStateMethods="true">
+    <component-class>org.apache.myfaces.custom.inputTextHelp.HtmlInputTextHelp</component-class>
+    <base-class>javax.faces.component.html.HtmlInputText</base-class>
+    <component-type>org.apache.myfaces.HtmlInputTextHelp</component-type>
+    <field>
+        <name>helpText</name>
+        <type>java.lang.String</type>
+    </field>
+    <field>
+        <name>selectText</name>
+        <type>boolean</type>
+    </field>
+</component>
\ No newline at end of file

Added: myfaces/trunk/src/components/org/apache/myfaces/custom/inputTextHelp/HtmlInputTextHelpTag.java
URL: http://svn.apache.org/viewcvs/myfaces/trunk/src/components/org/apache/myfaces/custom/inputTextHelp/HtmlInputTextHelpTag.java?rev=190263&view=auto
==============================================================================
--- myfaces/trunk/src/components/org/apache/myfaces/custom/inputTextHelp/HtmlInputTextHelpTag.java (added)
+++ myfaces/trunk/src/components/org/apache/myfaces/custom/inputTextHelp/HtmlInputTextHelpTag.java Sun Jun 12 05:41:16 2005
@@ -0,0 +1,50 @@
+package org.apache.myfaces.custom.inputTextHelp;
+
+import org.apache.myfaces.taglib.html.ext.HtmlInputTextTag;
+
+import javax.faces.component.UIComponent;
+
+/**
+ * @author Thomas Obereder
+ * @version Date: 09.06.2005, 22:16:41
+ */
+public class HtmlInputTextHelpTag extends HtmlInputTextTag
+{
+    private String _helpText = null;
+    private String _selectText = null;
+
+    public String getComponentType()
+    {
+        return HtmlInputTextHelp.COMPONENT_TYPE;
+    }
+
+    public String getRendererType()
+    {
+        return "org.apache.myfaces.TextHelp";
+    }
+
+    public void release()
+    {
+        super.release();
+
+        _helpText = null;
+        _selectText = null;
+    }
+
+    protected void setProperties(UIComponent component)
+    {
+        super.setProperties(component);
+        
+        setStringProperty(component, "helpText", _helpText);
+        setBooleanProperty(component, "selectText", _selectText);
+    }
+
+    public void setHelpText(String helpText)
+    {
+        _helpText = helpText;
+    }
+    public void setSelectText(String selectText)
+    {
+        _selectText = selectText;
+    }
+}

Added: myfaces/trunk/src/components/org/apache/myfaces/custom/inputTextHelp/HtmlTextHelpRenderer.java
URL: http://svn.apache.org/viewcvs/myfaces/trunk/src/components/org/apache/myfaces/custom/inputTextHelp/HtmlTextHelpRenderer.java?rev=190263&view=auto
==============================================================================
--- myfaces/trunk/src/components/org/apache/myfaces/custom/inputTextHelp/HtmlTextHelpRenderer.java (added)
+++ myfaces/trunk/src/components/org/apache/myfaces/custom/inputTextHelp/HtmlTextHelpRenderer.java Sun Jun 12 05:41:16 2005
@@ -0,0 +1,124 @@
+package org.apache.myfaces.custom.inputTextHelp;
+
+import org.apache.myfaces.renderkit.html.HtmlTextRendererBase;
+import org.apache.myfaces.renderkit.html.HtmlRendererUtils;
+import org.apache.myfaces.renderkit.html.HTML;
+import org.apache.myfaces.renderkit.html.ext.HtmlTextRenderer;
+import org.apache.myfaces.renderkit.html.util.HTMLEncoder;
+import org.apache.myfaces.renderkit.RendererUtils;
+import org.apache.myfaces.component.html.util.AddResource;
+
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIInput;
+
+import java.io.IOException;
+
+/**
+ * @author Thomas Obereder
+ * @version Date: 09.06.2005, 22:50:48
+ */
+public class HtmlTextHelpRenderer extends HtmlTextRenderer
+{
+    protected void renderNormal(FacesContext facesContext, UIComponent component) throws IOException
+    {
+        if(component instanceof HtmlInputTextHelp)
+        {
+            HtmlInputTextHelp helpTextComp = (HtmlInputTextHelp) component;
+            addJavaScriptResources(facesContext);
+            renderInputTextHelp(facesContext, (UIInput)helpTextComp);
+        }
+        else
+        {
+            super.renderNormal(facesContext, component);
+        }
+    }
+
+    public static boolean isSelectText(UIComponent component)
+    {
+        if(component instanceof HtmlInputTextHelp)
+        {
+            HtmlInputTextHelp helpTextComp = (HtmlInputTextHelp) component;
+            return helpTextComp.isSelectText();
+        }
+        return false;
+    }
+
+    public static String getHelpText(UIComponent component)
+    {
+        if(component instanceof HtmlInputTextHelp)
+        {
+            HtmlInputTextHelp helpTextComp = (HtmlInputTextHelp) component;
+            if(helpTextComp.getHelpText() != null)
+                return helpTextComp.getHelpText();
+        }
+        return null;
+    }
+
+    public static void renderInputTextHelp(FacesContext facesContext, UIInput input)
+            throws IOException
+    {
+        ResponseWriter writer = facesContext.getResponseWriter();
+
+        writer.startElement(HTML.INPUT_ELEM, input);
+
+        HtmlRendererUtils.writeIdIfNecessary(writer, input, facesContext);
+
+        renderHelpTextAttributes(input, writer, facesContext);
+
+        String value = RendererUtils.getStringValue(facesContext, input);
+        value = (value.equals("") || value == null) ? getHelpText(input) : "";
+
+        writer.writeAttribute(HTML.VALUE_ATTR, HTMLEncoder.encode(value,true,true), null);
+
+        writer.endElement(HTML.INPUT_ELEM);
+    }
+
+    public static void renderHelpTextAttributes(UIComponent component,
+                                                ResponseWriter writer,
+                                                FacesContext facesContext)
+            throws IOException
+    {
+        if(!(component instanceof HtmlInputTextHelp))
+        {
+            HtmlRendererUtils.renderHTMLAttributes(writer, component, HTML.COMMON_PASSTROUGH_ATTRIBUTES);
+            return;
+        }
+        else
+        {
+            String id = component.getClientId(facesContext);
+            if(isSelectText(component))
+            {
+                HtmlRendererUtils.renderHTMLAttributes(writer, component,
+                        HTML.COMMON_PASSTROUGH_ATTRIBUTES_WITHOUT_ONCLICK);
+                writer.writeAttribute(HTML.ONCLICK_ATTR,
+                        HtmlInputTextHelp.JS_FUNCTION_SELECT_TEXT + "('" +
+                            getHelpText(component) + "', '" + id +"')", null);
+            }
+            else
+            {
+                if(getHelpText(component) != null)
+                {
+                    HtmlRendererUtils.renderHTMLAttributes(writer, component,
+                            HTML.COMMON_PASSTROUGH_ATTRIBUTES_WITHOUT_ONCLICK);
+                    writer.writeAttribute(HTML.ONCLICK_ATTR,
+                            HtmlInputTextHelp.JS_FUNCTION_RESET_HELP + "('" +
+                            getHelpText(component) + "', '" + id +"')", null);
+                }
+                else
+                {
+                    HtmlRendererUtils.renderHTMLAttributes(writer,
+                            component, HTML.COMMON_PASSTROUGH_ATTRIBUTES);
+                }
+            }
+        }
+    }
+
+    private static void addJavaScriptResources(FacesContext facesContext) throws IOException
+    {
+        AddResource.addJavaScriptToHeader(HtmlTextHelpRenderer.class,
+                                            "inputTextHelp.js",
+                                            facesContext);
+    }
+}

Added: myfaces/trunk/src/components/org/apache/myfaces/custom/inputTextHelp/resource/inputTextHelp.js
URL: http://svn.apache.org/viewcvs/myfaces/trunk/src/components/org/apache/myfaces/custom/inputTextHelp/resource/inputTextHelp.js?rev=190263&view=auto
==============================================================================
--- myfaces/trunk/src/components/org/apache/myfaces/custom/inputTextHelp/resource/inputTextHelp.js (added)
+++ myfaces/trunk/src/components/org/apache/myfaces/custom/inputTextHelp/resource/inputTextHelp.js Sun Jun 12 05:41:16 2005
@@ -0,0 +1,17 @@
+function resetHelpValue(helpText, id)
+{
+    var element=document.getElementById(id);
+    if(element.value==helpText)
+    {
+        element.value="";
+    }
+}
+
+function selectText(helpText, id)
+{
+    var element=document.getElementById(id);
+    if(element.value==helpText)
+    {
+        element.select();
+    }
+}
\ No newline at end of file