You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ha...@apache.org on 2008/07/01 14:59:46 UTC
svn commit: r673073 - in
/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/selectOneRow:
./ AbstractSelectOneRow.java SelectOneRowRenderer.java
Author: hazems
Date: Tue Jul 1 05:59:45 2008
New Revision: 673073
URL: http://svn.apache.org/viewvc?rev=673073&view=rev
Log:
promoting the selectOneRow component to Tomahawk
http://issues.apache.org/jira/browse/TOMAHAWK-1293
Added:
myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/selectOneRow/
myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/selectOneRow/AbstractSelectOneRow.java
myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/selectOneRow/SelectOneRowRenderer.java
Added: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/selectOneRow/AbstractSelectOneRow.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/selectOneRow/AbstractSelectOneRow.java?rev=673073&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/selectOneRow/AbstractSelectOneRow.java (added)
+++ myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/selectOneRow/AbstractSelectOneRow.java Tue Jul 1 05:59:45 2008
@@ -0,0 +1,105 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.selectOneRow;
+
+import javax.faces.component.UIInput;
+
+import org.apache.myfaces.component.AlignProperty;
+
+/**
+ * Enhancement for a data-table to select one Row with a radio button. The row-index is stored in the vealu-binding
+ *
+ * @JSFComponent
+ * name = "t:selectOneRow"
+ * class = "org.apache.myfaces.custom.selectOneRow.SelectOneRow"
+ * tagClass = "org.apache.myfaces.custom.selectOneRow.SelectOneRowTag"
+ *
+ */
+public abstract class AbstractSelectOneRow extends UIInput
+ implements AlignProperty
+{
+
+ public static final String COMPONENT_TYPE = "org.apache.myfaces.SelectOneRow";
+
+ public static final String COMPONENT_FAMILY = "org.apache.myfaces.SelectOneRow";
+
+ public static final String DEFAULT_RENDERER_TYPE = "org.apache.myfaces.SelectOneRow";
+
+ /**
+ * The Name of the radio-button-group to use
+ *
+ * @JSFProperty
+ * literalOnly = "true"
+ */
+ public abstract String getGroupName();
+
+ /**
+ * HTML: When true, this element cannot receive focus.
+ *
+ * @JSFProperty
+ * defaultValue = "false"
+ */
+ public abstract boolean isDisabled();
+
+ /**
+ * HTML: When true, indicates that this component cannot be modified by the user.
+ * The element may receive focus unless it has also been disabled.
+ *
+ * @JSFProperty
+ * defaultValue = "false"
+ */
+ public abstract boolean isReadonly();
+
+ /**
+ * HTML: Specifies a script to be invoked when the element loses focus.
+ *
+ * @JSFProperty
+ */
+ public abstract String getOnblur();
+
+ /**
+ * HTML: Specifies a script to be invoked when the element receives focus.
+ *
+ * @JSFProperty
+ */
+ public abstract String getOnfocus();
+
+ /**
+ * HTML: Specifies a script to be invoked when the element is modified.
+ *
+ * @JSFProperty
+ */
+ public abstract String getOnchange();
+
+
+ /**
+ * HTML: Specifies a script to be invoked when the element is selected.
+ *
+ * @JSFProperty
+ */
+ public abstract String getOnselect();
+
+ /**
+ * HTML: Script to be invoked when the element is clicked.
+ *
+ * @JSFProperty
+ */
+ public abstract String getOnclick();
+
+}
Added: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/selectOneRow/SelectOneRowRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/selectOneRow/SelectOneRowRenderer.java?rev=673073&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/selectOneRow/SelectOneRowRenderer.java (added)
+++ myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/selectOneRow/SelectOneRowRenderer.java Tue Jul 1 05:59:45 2008
@@ -0,0 +1,141 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.selectOneRow;
+
+import org.apache.myfaces.shared_tomahawk.renderkit.html.HtmlRenderer;
+import org.apache.myfaces.shared_tomahawk.renderkit.html.HTML;
+import org.apache.myfaces.shared_tomahawk.renderkit.html.HtmlRendererUtils;
+
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIData;
+import javax.faces.component.UIInput;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+import java.io.IOException;
+import java.util.Map;
+
+/**
+ *
+ * @JSFRenderer
+ * renderKitId = "HTML_BASIC"
+ * family = "org.apache.myfaces.SelectOneRow"
+ * type = "org.apache.myfaces.SelectOneRow"
+ *
+ */
+public class SelectOneRowRenderer extends HtmlRenderer
+{
+
+ public void encodeBegin(FacesContext facesContext, UIComponent component) throws IOException
+ {
+ if ((component instanceof SelectOneRow) && component.isRendered())
+ {
+ SelectOneRow row = (SelectOneRow) component;
+ String clientId = row.getClientId(facesContext);
+
+ 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);
+
+ // 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();
+
+ 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);
+ }
+ }
+ }
+}