You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by bo...@apache.org on 2008/07/02 22:25:37 UTC

svn commit: r673483 - in /myfaces/tobago/branches/tobago-1.0.x: core/src/main/java/org/apache/myfaces/tobago/taglib/component/ theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/ theme/standard/src/main/re...

Author: bommel
Date: Wed Jul  2 13:25:36 2008
New Revision: 673483

URL: http://svn.apache.org/viewvc?rev=673483&view=rev
Log:
(TOBAGO-687) Readonly support for tc:selectOneRadio

Modified:
    myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/taglib/component/SelectOneRadioTagDeclaration.java
    myfaces/tobago/branches/tobago-1.0.x/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/SelectOneRadioRenderer.java
    myfaces/tobago/branches/tobago-1.0.x/theme/standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago.js

Modified: myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/taglib/component/SelectOneRadioTagDeclaration.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/taglib/component/SelectOneRadioTagDeclaration.java?rev=673483&r1=673482&r2=673483&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/taglib/component/SelectOneRadioTagDeclaration.java (original)
+++ myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/taglib/component/SelectOneRadioTagDeclaration.java Wed Jul  2 13:25:36 2008
@@ -30,6 +30,7 @@
 import org.apache.myfaces.tobago.taglib.decl.IsInline;
 import org.apache.myfaces.tobago.taglib.decl.IsRendered;
 import org.apache.myfaces.tobago.taglib.decl.HasConverter;
+import org.apache.myfaces.tobago.taglib.decl.IsReadonly;
 
 /*
  * Created: Aug 5, 2005 6:11:03 PM
@@ -53,7 +54,7 @@
             "This facet can contain a UICommand that is invoked in case of a change event from the component")
         })
 public interface SelectOneRadioTagDeclaration extends SelectOneTagDeclaration, IsDisabled, HasId,
-    IsInline, HasRenderRange, IsRendered, HasBinding, HasConverter {
+    IsInline, HasRenderRange, IsRendered, HasBinding, HasConverter, IsReadonly {
 
   /**
    * Flag indicating that selecting an Item representing a Value is Required.

Modified: myfaces/tobago/branches/tobago-1.0.x/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/SelectOneRadioRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-1.0.x/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/SelectOneRadioRenderer.java?rev=673483&r1=673482&r2=673483&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-1.0.x/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/SelectOneRadioRenderer.java (original)
+++ myfaces/tobago/branches/tobago-1.0.x/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/SelectOneRadioRenderer.java Wed Jul  2 13:25:36 2008
@@ -24,9 +24,10 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import static org.apache.myfaces.tobago.TobagoConstants.ATTR_DISABLED;
 import static org.apache.myfaces.tobago.TobagoConstants.ATTR_INLINE;
+import static org.apache.myfaces.tobago.TobagoConstants.ATTR_READONLY;
 import static org.apache.myfaces.tobago.TobagoConstants.ATTR_REQUIRED;
-import static org.apache.myfaces.tobago.TobagoConstants.ATTR_DISABLED;
 import org.apache.myfaces.tobago.component.ComponentUtil;
 import org.apache.myfaces.tobago.component.UISelectOne;
 import org.apache.myfaces.tobago.renderkit.RenderUtil;
@@ -96,6 +97,7 @@
     }
 
     boolean disabled = ComponentUtil.getBooleanAttribute(selectOne, ATTR_DISABLED);
+    boolean readonly = ComponentUtil.getBooleanAttribute(selectOne, ATTR_READONLY);
     Object value = selectOne.getValue();
     List<String> clientIds = new ArrayList<String>();
     for (SelectItem item : items) {
@@ -111,7 +113,8 @@
       writer.startElement(HtmlConstants.INPUT, selectOne);
       writer.writeAttribute(HtmlAttributes.TYPE, "radio", false);
       writer.writeClassAttribute();
-      if (item.getValue().equals(value)) {
+      boolean checked = item.getValue().equals(value);
+      if (checked) {
         writer.writeAttribute(HtmlAttributes.CHECKED, "checked", false);
       }
       writer.writeNameAttribute(clientId);
@@ -125,8 +128,10 @@
         writer.writeAttribute(HtmlAttributes.TABINDEX, tabIndex);
       }
       HtmlRendererUtil.renderTip(selectOne, writer);
-      if (!ComponentUtil.getBooleanAttribute(selectOne, ATTR_REQUIRED)) {
-        writer.writeAttribute(HtmlAttributes.ONCLICK, "Tobago.selectOneRadioClick(this, '" + clientId + "')", false);
+      if (!ComponentUtil.getBooleanAttribute(selectOne, ATTR_REQUIRED) || readonly) {
+        writer.writeAttribute(HtmlAttributes.ONCLICK,
+            "Tobago.selectOneRadioClick(this, '" + clientId + "',"
+                + ComponentUtil.getBooleanAttribute(selectOne, ATTR_REQUIRED) + " , " + readonly + ")", false);
       }
       writer.endElement(HtmlConstants.INPUT);
 
@@ -147,6 +152,9 @@
         if (item.isDisabled() || disabled) {
           styleClasses.addAspectClass("label", StyleClasses.Aspect.DISABLED);
         }
+        if (readonly) {
+          styleClasses.addAspectClass("label", StyleClasses.Aspect.READONLY);
+        }
         writer.writeClassAttribute(styleClasses);
         writer.writeAttribute(HtmlAttributes.FOR, id, false);
         writer.writeText(item.getLabel());

Modified: myfaces/tobago/branches/tobago-1.0.x/theme/standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago.js
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-1.0.x/theme/standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago.js?rev=673483&r1=673482&r2=673483&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-1.0.x/theme/standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago.js (original)
+++ myfaces/tobago/branches/tobago-1.0.x/theme/standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago.js Wed Jul  2 13:25:36 2008
@@ -850,20 +850,26 @@
   },
 
   /**
-    * Onclick function for SelectOneradio.
+    * Onclick function for SelectOneRadio.
     */
-  selectOneRadioClick: function(element, name) {
+  selectOneRadioClick: function(element, name, required, readonly) {
     var elements = document.getElementsByName(name);
     for (var i = 0; i < elements.length; i++) {
-      if (elements[i] != element) {
-        elements[i].checked = false;
-        elements[i].oldValue = false;
+      if (readonly) {
+        elements[i].checked = elements[i].oldValue;
+      } else {
+        if (elements[i] != element) {
+          elements[i].checked = false;
+          elements[i].oldValue = false;
+        }
       }
     }
-    if (element.oldValue == element.checked) {
-      element.checked = false;
+    if (!required && !readonly) {
+      if (element.oldValue == element.checked) {
+        element.checked = false;
+      }
+      element.oldValue = element.checked;
     }
-    element.oldValue = element.checked;
   },
 
 // -------- Popup functions ---------------------------------------------------