You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lf...@apache.org on 2006/09/28 03:46:55 UTC

svn commit: r450661 - in /myfaces/tomahawk/trunk/core/src/main: java/org/apache/myfaces/custom/document/ tld/tomahawk-entities/

Author: lfrohman
Date: Wed Sep 27 18:46:54 2006
New Revision: 450661

URL: http://svn.apache.org/viewvc?view=rev&rev=450661
Log:
resolve TOMAHAWK-706: add onload, onunload, onresize, onkeypress to <t:documentBody>

Modified:
    myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/document/DocumentBody.java
    myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/document/DocumentBodyRenderer.java
    myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/document/DocumentBodyTag.java
    myfaces/tomahawk/trunk/core/src/main/tld/tomahawk-entities/tomahawk_document_body_attributes.xml

Modified: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/document/DocumentBody.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/document/DocumentBody.java?view=diff&rev=450661&r1=450660&r2=450661
==============================================================================
--- myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/document/DocumentBody.java (original)
+++ myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/document/DocumentBody.java Wed Sep 27 18:46:54 2006
@@ -14,7 +14,9 @@
  * limitations under the License.
  */
 package org.apache.myfaces.custom.document;
-
+import javax.faces.context.FacesContext;
+import javax.faces.el.ValueBinding;
+import org.apache.myfaces.shared_tomahawk.util._ComponentUtils;
 
 /**
  * Document to enclose the document body. If not otherwise possible you can use
@@ -27,9 +29,88 @@
 {
 	public static final String COMPONENT_TYPE = "org.apache.myfaces.DocumentBody";
 	private static final String DEFAULT_RENDERER_TYPE = DocumentBodyRenderer.RENDERER_TYPE;
+    private String _onload;
+    private String _onunload;
+    private String _onresize;
+    private String _onkeypress;
 
 	public DocumentBody()
 	{
 		super(DEFAULT_RENDERER_TYPE);
 	}
+
+    /**
+     * @param localValue
+     * @param valueBindingName
+     * @return the value
+     */
+    private Object getLocalOrValueBindingValue(Object localValue,
+                    String valueBindingName)
+    {
+        if (localValue != null)
+            return localValue;
+        ValueBinding vb = getValueBinding(valueBindingName);
+        return vb != null ? vb.getValue(getFacesContext()) : null;
+    }
+
+    public void setOnload(String onload)
+    {
+        _onload = onload;
+    }
+
+    public String getOnload()
+    {
+        return (String) getLocalOrValueBindingValue(_onload, "onload");
+    }
+
+    public void setOnunload(String onunload)
+    {
+        _onunload = onunload;
+    }
+
+    public String getOnunload()
+    {
+        return (String) getLocalOrValueBindingValue(_onunload, "onunload");
+    }
+
+    public void setOnresize(String onresize)
+    {
+        _onresize = onresize;
+    }
+
+    public String getOnresize()
+    {
+        return (String) getLocalOrValueBindingValue(_onresize, "onresize");
+    }
+
+    public void setOnkeypress(String onkeypress)
+    {
+        _onkeypress = onkeypress;
+    }
+
+    public String getOnkeypress()
+    {
+        return (String) getLocalOrValueBindingValue(_onkeypress, "onkeypress");
+    }
+
+    public Object saveState(FacesContext context)
+    {
+        Object[] values = new Object[5];
+        values[0] = super.saveState(context);
+        values[1] = _onload;
+        values[2] = _onunload;
+        values[3] = _onresize;
+        values[4] = _onkeypress;
+        return values;
+    }
+
+    public void restoreState(FacesContext context, Object state)
+    {
+        Object[] values = (Object[]) state;
+        super.restoreState(context, values[0]);
+        _onload = (String) values[1];
+        _onunload = (String) values[2];
+        _onresize = (String) values[3];
+        _onkeypress = (String) values[4];
+    }
 }

Modified: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/document/DocumentBodyRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/document/DocumentBodyRenderer.java?view=diff&rev=450661&r1=450660&r2=450661
==============================================================================
--- myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/document/DocumentBodyRenderer.java (original)
+++ myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/document/DocumentBodyRenderer.java Wed Sep 27 18:46:54 2006
@@ -16,10 +16,11 @@
 package org.apache.myfaces.custom.document;
 
 import java.io.IOException;
-
+import javax.faces.component.UIComponent;
 import javax.faces.context.FacesContext;
-
+import javax.faces.context.ResponseWriter;
 import org.apache.myfaces.renderkit.html.util.ExtensionsPhaseListener;
+import org.apache.myfaces.shared_tomahawk.renderkit.html.HtmlRendererUtils;
 
 /**
  * Document to enclose the whole document. If not otherwise possible you can use
@@ -31,16 +32,27 @@
 public class DocumentBodyRenderer extends AbstractDocumentRenderer
 {
 	public static final String RENDERER_TYPE = "org.apache.myfaces.DocumentBody";
+	private String BODY_ELEM = "body";
+	private String[] ATTRS = new String[] {"onload", "onunload", "onresize", "onkeypress"};
 
 	protected String getHtmlTag()
 	{
-		return "body";
+		return BODY_ELEM;
 	}
 
 	protected Class getDocumentClass()
 	{
 		return DocumentBody.class;
 	}
+
+    public void encodeEnd(FacesContext facesContext, UIComponent uiComponent)
+    	throws IOException
+    {
+        ResponseWriter writer = facesContext.getResponseWriter();
+        writer.startElement(BODY_ELEM, uiComponent);
+        HtmlRendererUtils.renderHTMLAttributes(writer, uiComponent, ATTRS);
+        writer.endElement(BODY_ELEM);
+    }
 
 	protected void writeBeforeEnd(FacesContext facesContext) throws IOException
 	{

Modified: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/document/DocumentBodyTag.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/document/DocumentBodyTag.java?view=diff&rev=450661&r1=450660&r2=450661
==============================================================================
--- myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/document/DocumentBodyTag.java (original)
+++ myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/document/DocumentBodyTag.java Wed Sep 27 18:46:54 2006
@@ -14,6 +14,7 @@
  * limitations under the License.
  */
 package org.apache.myfaces.custom.document;
+import javax.faces.component.UIComponent;
 
 /**
  * Document to enclose the whole document. If not otherwise possible you can use
@@ -24,7 +25,12 @@
  */
 public class DocumentBodyTag extends AbstractDocumentTag
 {
-	public String getComponentType()
+    private String _onload;
+    private String _onunload;
+    private String _onresize;
+    private String _onkeypress;
+
+    public String getComponentType()
 	{
 		return DocumentBody.COMPONENT_TYPE;
 	}
@@ -33,4 +39,36 @@
 	{
 		return DocumentBodyRenderer.RENDERER_TYPE;
 	}
+
+    public void release() {
+        super.release();
+        _onload = null;
+        _onunload = null;
+        _onresize = null;
+        _onkeypress = null;
+    }
+
+    protected void setProperties(UIComponent component) {
+        super.setProperties(component);
+        setStringProperty(component, "onload", _onload);
+        setStringProperty(component, "onunload", _onunload);
+        setStringProperty(component, "onresize", _onresize);
+        setStringProperty(component, "onkeypress", _onkeypress);
+    }
+
+    public void setOnload(String onload) {
+        _onload = onload;
+    }
+
+    public void setOnunload(String onunload) {
+        _onunload = onunload;
+    }
+
+    public void setOnresize(String onresize) {
+        _onresize = onresize;
+    }
+
+    public void setOnkeypress(String onkeypress) {
+        _onkeypress = onkeypress;
+    }
 }

Modified: myfaces/tomahawk/trunk/core/src/main/tld/tomahawk-entities/tomahawk_document_body_attributes.xml
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/main/tld/tomahawk-entities/tomahawk_document_body_attributes.xml?view=diff&rev=450661&r1=450660&r2=450661
==============================================================================
--- myfaces/tomahawk/trunk/core/src/main/tld/tomahawk-entities/tomahawk_document_body_attributes.xml (original)
+++ myfaces/tomahawk/trunk/core/src/main/tld/tomahawk-entities/tomahawk_document_body_attributes.xml Wed Sep 27 18:46:54 2006
@@ -3,3 +3,24 @@
             <required>false</required>
             <rtexprvalue>false</rtexprvalue>
         </attribute>
+        <attribute>
+            <name>onload</name>
+            <required>false</required>
+            <rtexprvalue>false</rtexprvalue>
+        </attribute>
+        <attribute>
+            <name>onunload</name>
+            <required>false</required>
+            <rtexprvalue>false</rtexprvalue>
+        </attribute>
+        <attribute>
+            <name>onresize</name>
+            <required>false</required>
+            <rtexprvalue>false</rtexprvalue>
+        </attribute>
+        <attribute>
+            <name>onkeypress</name>
+            <required>false</required>
+            <rtexprvalue>false</rtexprvalue>
+        </attribute>
+        
\ No newline at end of file