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 2006/02/27 18:39:01 UTC

svn commit: r381394 - in /myfaces/tomahawk/trunk/sandbox/core/src/main: java/org/apache/myfaces/custom/selectOneRow/ tld/ tld/entities-share/html_attributes/

Author: mmarinschek
Date: Mon Feb 27 09:38:57 2006
New Revision: 381394

URL: http://svn.apache.org/viewcvs?rev=381394&view=rev
Log:
select one row now works with onclick

Added:
    myfaces/tomahawk/trunk/sandbox/core/src/main/tld/entities-share/html_attributes/onclick.xml
Modified:
    myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/selectOneRow/SelectOneRow.java
    myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/selectOneRow/SelectOneRowRenderer.java
    myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/selectOneRow/SelectOneRowTag.java
    myfaces/tomahawk/trunk/sandbox/core/src/main/tld/myfaces_sandbox.tld

Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/selectOneRow/SelectOneRow.java
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/selectOneRow/SelectOneRow.java?rev=381394&r1=381393&r2=381394&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/selectOneRow/SelectOneRow.java (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/selectOneRow/SelectOneRow.java Mon Feb 27 09:38:57 2006
@@ -16,41 +16,47 @@
 {
     private String groupName;
 
- public static final String COMPONENT_TYPE = "org.apache.myfaces.SelectOneRow";
+    public static final String COMPONENT_TYPE = "org.apache.myfaces.SelectOneRow";
 
- public static final String COMPONENT_FAMILY = "org.apache.myfaces.SelectOneRow";
+    public static final String COMPONENT_FAMILY = "org.apache.myfaces.SelectOneRow";
 
- private static final String DEFAULT_RENDERER_TYPE = "org.apache.myfaces.SelectOneRow";
+    public static final String DEFAULT_RENDERER_TYPE = "org.apache.myfaces.SelectOneRow";
 
- public SelectOneRow() {
-  setRendererType(DEFAULT_RENDERER_TYPE);
- }
+    public SelectOneRow()
+    {
+        setRendererType(DEFAULT_RENDERER_TYPE);
+    }
+
+    public String getFamily()
+    {
+        return COMPONENT_FAMILY;
+    }
+
+    public String getGroupName()
+    {
+        return groupName;
+    }
+
+    public void setGroupName(String groupName)
+    {
+        this.groupName = groupName;
+    }
+
+    public void restoreState(FacesContext context, Object state)
+    {
+
+        Object[] values = (Object[]) state;
+        super.restoreState(context, values[0]);
+        groupName = (String) values[1];
+
+    }
+
+    public Object saveState(FacesContext context)
+    {
+        Object[] values = new Object[2];
+        values[0] = super.saveState(context);
+        values[1] = groupName;
+        return values;
+    }
 
- public String getFamily() {
-  return COMPONENT_FAMILY;
- }
-
- public String getGroupName() {
-  return groupName;
- }
-
- public void setGroupName(String groupName) {
-  this.groupName = groupName;
- }
-
- public void restoreState(FacesContext context, Object state) {
-
-  Object[] values = (Object[]) state;
-  super.restoreState(context, values[0]);
-  groupName = (String) values[1];
-
- }
-
- public Object saveState(FacesContext context) {
-  Object[] values = new Object[2];
-  values[0] = super.saveState(context);
-  values[1] = groupName;
-  return values;
- }
- 
 }

Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/selectOneRow/SelectOneRowRenderer.java
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/selectOneRow/SelectOneRowRenderer.java?rev=381394&r1=381393&r2=381394&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/selectOneRow/SelectOneRowRenderer.java (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/selectOneRow/SelectOneRowRenderer.java Mon Feb 27 09:38:57 2006
@@ -21,7 +21,6 @@
  */
 public class SelectOneRowRenderer extends HtmlRenderer
 {
-    private static final String DEFAULT_RENDERER_TYPE = "org.apache.myfaces.SelectOneRow";
 
     public void encodeBegin(FacesContext facesContext, UIComponent component) throws IOException
     {
@@ -30,86 +29,94 @@
             SelectOneRow row = (SelectOneRow) component;
             String clientId = row.getClientId(facesContext);
 
-        ResponseWriter writer = facesContext.getResponseWriter();
+            ResponseWriter writer = facesContext.getResponseWriter();
 
-        writer.startElement(HTML.INPUT_ELEM, row);
-        writer.writeAttribute(HTML.TYPE_ATTR, HTML.INPUT_TYPE_RADIO, null);
-        writer.writeAttribute(HTML.NAME_ATTR, row.getGroupName(), null);
+            writer.startElement(HTML.INPUT_ELEM, row);
+            writer.writeAttribute(HTML.TYPE_ATTR, HTML.INPUT_TYPE_RADIO, null);
+            writer.writeAttribute(HTML.NAME_ATTR, row.getGroupName(), null);
 
-        if (false) { // todo: disabled Attribute
-            writer.writeAttribute(HTML.DISABLED_ATTR, HTML.DISABLED_ATTR, null);
+            // todo: disabled Attribute
+            //writer.writeAttribute(HTML.DISABLED_ATTR, HTML.DISABLED_ATTR, null);
+
+            writer.writeAttribute(HTML.ID_ATTR, clientId, null);
+
+            if (isRowSelected(row))
+            {
+                writer.writeAttribute(HTML.CHECKED_ATTR, HTML.CHECKED_ATTR, null);
+            }
+
+            writer.writeAttribute(HTML.VALUE_ATTR, clientId, null);
+
+            HtmlRendererUtils.renderHTMLAttributes(writer, row, HTML.INPUT_PASSTHROUGH_ATTRIBUTES_WITHOUT_DISABLED);
+
+            HtmlRendererUtils.renderHTMLAttributes(writer, row, new String[]{HTML.ONCLICK_ATTR});
+
+            writer.endElement(HTML.INPUT_ELEM);
         }
+    }
+
+    private boolean isRowSelected(UIComponent component)
+    {
+        UIInput input = (UIInput) component;
+        Object value = input.getValue();
 
-        writer.writeAttribute(HTML.ID_ATTR, clientId, null);
+        int currentRowIndex = getCurrentRowIndex(component);
+
+        return (value != null)
+                && (currentRowIndex == ((Long) value).intValue());
+
+    }
 
-        if (isRowSelected(row))
+    private int getCurrentRowIndex(UIComponent component)
+    {
+        UIData uidata = findUIData(component);
+        if (uidata == null)
+            return -1;
+        else
+            return uidata.getRowIndex();
+    }
+
+    protected UIData findUIData(UIComponent uicomponent)
+    {
+        if (uicomponent == null)
+            return null;
+        if (uicomponent instanceof UIData)
+            return (UIData) uicomponent;
+        else
+            return findUIData(uicomponent.getParent());
+    }
+
+    public void decode(FacesContext context, UIComponent uiComponent)
+    {
+        if (! (uiComponent instanceof SelectOneRow))
         {
-            writer.writeAttribute(HTML.CHECKED_ATTR, HTML.CHECKED_ATTR, null);
+            return;
         }
 
-            writer.writeAttribute(HTML.VALUE_ATTR, clientId, null);
+        if (!uiComponent.isRendered())
+        {
+            return;
+        }
+        SelectOneRow row = (SelectOneRow) uiComponent;
 
-        HtmlRendererUtils.renderHTMLAttributes(writer, row, HTML.INPUT_PASSTHROUGH_ATTRIBUTES_WITHOUT_DISABLED);
+        Map requestMap = context.getExternalContext().getRequestParameterMap();
+        String postedValue;
 
-        writer.endElement(HTML.INPUT_ELEM);
+        if (requestMap.containsKey(row.getGroupName()))
+        {
+            postedValue = (String) requestMap.get(row.getGroupName());
+            String clientId = row.getClientId(context);
+            if (clientId.equals(postedValue))
+            {
+
+                String[] postedValueArray = postedValue.split(":");
+                String rowIndex = postedValueArray[postedValueArray.length - 2];
+
+                Long newValue = Long.valueOf(rowIndex);
+                //the value to go in conversion&validation
+                row.setSubmittedValue(newValue);
+                row.setValid(true);
+            }
         }
     }
-
- private boolean isRowSelected(UIComponent component) {
-  UIInput input = (UIInput) component;
-  Object value = input.getValue();
-
-  int currentRowIndex = getCurrentRowIndex(component);
-
-  return (value != null)
-    && (currentRowIndex == ((Long) value).intValue());
-
- }
-
- private int getCurrentRowIndex(UIComponent component) {
-  UIData uidata = findUIData(component);
-  if (uidata == null)
-   return -1;
-  else
-   return uidata.getRowIndex();
- }
-
- protected UIData findUIData(UIComponent uicomponent) {
-  if (uicomponent == null)
-   return null;
-  if (uicomponent instanceof UIData)
-   return (UIData) uicomponent;
-  else
-   return findUIData(uicomponent.getParent());
- }
-
- public void decode(FacesContext context, UIComponent uiComponent) {
-  if(! (uiComponent instanceof SelectOneRow) )
-  {
-      return;
-  }
-
-  if (!uiComponent.isRendered()) {
-   return;
-  }
-  SelectOneRow row = (SelectOneRow) uiComponent;
-
-  Map requestMap = context.getExternalContext().getRequestParameterMap();
-  String postedValue;
-
-  if (requestMap.containsKey(row.getGroupName())) {
-   postedValue = (String) requestMap.get(row.getGroupName());
-   String clientId = row.getClientId(context);
-   if (clientId.equals(postedValue)) {
-
-    String[] postedValueArray = postedValue.split(":");
-    String rowIndex = postedValueArray[postedValueArray.length - 2];
-
-    Long newValue = Long.valueOf(rowIndex);
-    //the value to go in conversion&validation
-    row.setSubmittedValue(newValue);
-    row.setValid(true);
-   }
-  }
- }
 }

Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/selectOneRow/SelectOneRowTag.java
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/selectOneRow/SelectOneRowTag.java?rev=381394&r1=381393&r2=381394&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/selectOneRow/SelectOneRowTag.java (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/selectOneRow/SelectOneRowTag.java Mon Feb 27 09:38:57 2006
@@ -4,6 +4,7 @@
 
 import org.apache.myfaces.renderkit.JSFAttr;
 import org.apache.myfaces.renderkit.html.HTML;
+
 import javax.faces.application.Application;
 import javax.faces.component.UIComponent;
 import javax.faces.component.UIInput;
@@ -19,7 +20,16 @@
  */
 public class SelectOneRowTag extends HtmlInputTagBase
 {
-    private static final String DEFAULT_RENDERER_TYPE = "org.apache.myfaces.SelectOneRow";
+    public String getComponentType()
+    {
+        return SelectOneRow.COMPONENT_TYPE;
+    }
+
+    public String getRendererType()
+    {
+        return SelectOneRow.DEFAULT_RENDERER_TYPE;
+    }
+
 // UIComponent attributes --> already implemented in UIComponentTagBase
 
     // user role attributes --> already implemented in UIComponentTagBase
@@ -39,6 +49,7 @@
     private String _maxlength;
     private String _onblur;
     private String _onchange;
+    private String _onclick;
     private String _onfocus;
     private String _onselect;
     private String _readonly;
@@ -54,23 +65,25 @@
     // HTMLInputSecret attributes
     private String _groupName;
 
-    public void release() {
+    public void release()
+    {
         super.release();
-        _accesskey=null;
-        _align=null;
-        _alt=null;
-        _datafld=null;
-        _datasrc=null;
-        _dataformatas=null;
-        _disabled=null;
-        _maxlength=null;
-        _onblur=null;
-        _onchange=null;
-        _onfocus=null;
-        _onselect=null;
-        _readonly=null;
-        _size=null;
-        _tabindex=null;
+        _accesskey = null;
+        _align = null;
+        _alt = null;
+        _datafld = null;
+        _datasrc = null;
+        _dataformatas = null;
+        _disabled = null;
+        _maxlength = null;
+        _onblur = null;
+        _onchange = null;
+        _onclick = null;
+        _onfocus = null;
+        _onselect = null;
+        _readonly = null;
+        _size = null;
+        _tabindex = null;
         _groupName = null;
     }
 
@@ -88,27 +101,30 @@
         setIntegerProperty(component, HTML.MAXLENGTH_ATTR, _maxlength);
         setStringProperty(component, HTML.ONBLUR_ATTR, _onblur);
         setStringProperty(component, HTML.ONCHANGE_ATTR, _onchange);
+        setStringProperty(component, HTML.ONCLICK_ATTR, _onclick);
         setStringProperty(component, HTML.ONFOCUS_ATTR, _onfocus);
         setStringProperty(component, HTML.ONSELECT_ATTR, _onselect);
         setBooleanProperty(component, HTML.READONLY_ATTR, _readonly);
         setIntegerProperty(component, HTML.SIZE_ATTR, _size);
         setStringProperty(component, HTML.TABINDEX_ATTR, _tabindex);
 
-            UIInput singleInputRowSelect = (UIInput) component;
-          singleInputRowSelect.getAttributes().put("groupName", _groupName);
+        UIInput singleInputRowSelect = (UIInput) component;
+        singleInputRowSelect.getAttributes().put("groupName", _groupName);
 
-          if (getValue() != null) {
+        if (getValue() != null)
+        {
 
-           if (isValueReference(getValue())) {
-            FacesContext context = FacesContext.getCurrentInstance();
-            Application app = context.getApplication();
-            ValueBinding binding = app.createValueBinding(getValue());
-            singleInputRowSelect.setValueBinding("value",binding);
+            if (isValueReference(getValue()))
+            {
+                FacesContext context = FacesContext.getCurrentInstance();
+                Application app = context.getApplication();
+                ValueBinding binding = app.createValueBinding(getValue());
+                singleInputRowSelect.setValueBinding("value", binding);
 
-           }
+            }
 
-          }
-   }
+        }
+    }
 
     public void setAccesskey(String accesskey)
     {
@@ -160,6 +176,11 @@
         _onchange = onchange;
     }
 
+    public void setOnclick(String onclick)
+    {
+        _onclick = onclick;
+    }
+
     public void setOnfocus(String onfocus)
     {
         _onfocus = onfocus;
@@ -186,33 +207,22 @@
     }
 
 
+    public String getValue()
+    {
+        return value;
+    }
 
- public String getValue() {
-  return value;
- }
-
- public void setValue(String value) {
-  this.value = value;
- }
-
- private String value;
-
- public String getComponentType() {
-
-  return SelectOneRow.COMPONENT_TYPE;
- }
-
- public String getRendererType() {
-  return DEFAULT_RENDERER_TYPE;
- }
+    public void setValue(String value)
+    {
+        this.value = value;
+    }
 
- public String getGroupName() {
-  return _groupName;
- }
+    private String value;
 
- public void setGroupName(String groupName) {
-  this._groupName = groupName;
- }
+    public void setGroupName(String groupName)
+    {
+        this._groupName = groupName;
+    }
 
 
 }

Added: myfaces/tomahawk/trunk/sandbox/core/src/main/tld/entities-share/html_attributes/onclick.xml
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/sandbox/core/src/main/tld/entities-share/html_attributes/onclick.xml?rev=381394&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/tld/entities-share/html_attributes/onclick.xml (added)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/tld/entities-share/html_attributes/onclick.xml Mon Feb 27 09:38:57 2006
@@ -0,0 +1,7 @@
+<attribute>
+    <name>onclick</name>
+    <required>false</required>
+    <rtexprvalue>false</rtexprvalue>
+    <type>java.lang.String</type>
+    <description>HTML: Specifies a script to be invoked when the element is clicked on.</description>
+</attribute>

Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/tld/myfaces_sandbox.tld
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/sandbox/core/src/main/tld/myfaces_sandbox.tld?rev=381394&r1=381393&r2=381394&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/tld/myfaces_sandbox.tld (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/tld/myfaces_sandbox.tld Mon Feb 27 09:38:57 2006
@@ -61,6 +61,7 @@
 <!ENTITY html_input_radio_attributes    SYSTEM "entities-share/html_input_radio_attributes.xml">
 <!ENTITY html_label_attributes          SYSTEM "entities-share/html_label_attributes.xml">
 <!ENTITY html_onchange_attribute        SYSTEM "entities-share/html_attributes/onchange.xml">
+<!ENTITY html_onclick_attribute         SYSTEM "entities-share/html_attributes/onclick.xml">
 <!ENTITY html_onselect_attribute        SYSTEM "entities-share/html_attributes/onselect.xml">
 <!ENTITY html_readonly_attribute        SYSTEM "entities-share/html_attributes/readonly.xml">
 <!ENTITY html_tabindex_attribute        SYSTEM "entities-share/html_attributes/tabindex.xml">
@@ -925,6 +926,7 @@
         &html_disabled_attribute;
         &html_focus_blur_attributes;
         &html_onchange_attribute;
+        &html_onclick_attribute;
         &html_onselect_attribute;
         &html_readonly_attribute;
         &ui_input_attributes;