You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by sk...@apache.org on 2008/07/04 00:03:31 UTC
svn commit: r673836 [3/8] - in /myfaces/tomahawk/trunk:
core/src/main/java/org/apache/myfaces/custom/buffer/
core/src/main/java/org/apache/myfaces/custom/calendar/
core/src/main/java/org/apache/myfaces/custom/captcha/
core/src/main/java/org/apache/myfa...
Modified: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/picklist/HtmlPicklistRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/picklist/HtmlPicklistRenderer.java?rev=673836&r1=673835&r2=673836&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/picklist/HtmlPicklistRenderer.java (original)
+++ myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/picklist/HtmlPicklistRenderer.java Thu Jul 3 15:03:29 2008
@@ -1,340 +1,340 @@
-/*
- * 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.picklist;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import javax.faces.component.EditableValueHolder;
-import javax.faces.component.UIComponent;
-import javax.faces.component.UISelectMany;
-import javax.faces.context.FacesContext;
-import javax.faces.context.ResponseWriter;
-import javax.faces.convert.Converter;
-import javax.faces.model.SelectItem;
-
-import org.apache.commons.collections.CollectionUtils;
-import org.apache.myfaces.renderkit.html.util.AddResource;
-import org.apache.myfaces.renderkit.html.util.AddResourceFactory;
-import org.apache.myfaces.shared_tomahawk.renderkit.html.HTML;
-import org.apache.myfaces.shared_tomahawk.renderkit.JSFAttr;
-import org.apache.myfaces.shared_tomahawk.renderkit.RendererUtils;
-import org.apache.myfaces.shared_tomahawk.renderkit.html.HtmlRendererUtils;
-import org.apache.myfaces.shared_tomahawk.renderkit.html.HtmlListboxRendererBase;
-
-/**
- *
- * @JSFRenderer
- * renderKitId = "HTML_BASIC"
- * family = "javax.faces.SelectMany"
- * type = "org.apache.myfaces.PicklistRenderer"
- *
- * @author Bruno Aranda (latest modification by $Author$)
- * @version $Revision$ $Date$
- */
-public class HtmlPicklistRenderer extends HtmlListboxRendererBase
-{
-
- private static final String FUNCTION_ADD_TO_SELECTED = "myfaces_picklist_addToSelected";
- private static final String FUNCTION_REMOVE_FROM_SELECTED = "myfaces_picklist_removeFromSelected";
-
- private static final String AVAILABLE_SUFFIX = "_AVAILABLE";
- private static final String SELECTED_SUFFIX = "_SELECTED";
- private static final String HIDDEN_SUFFIX = "_HIDDEN";
-
- public void decode(FacesContext facesContext, UIComponent uiComponent)
- {
- RendererUtils.checkParamValidity(facesContext, uiComponent, null);
-
- if (!(uiComponent instanceof EditableValueHolder))
- {
- throw new IllegalArgumentException("Component "
- + uiComponent.getClientId(facesContext)
- + " is not an EditableValueHolder");
- }
-
- String hiddenClientId = uiComponent.getClientId(facesContext)
- + HIDDEN_SUFFIX;
-
- Map paramValuesMap = facesContext.getExternalContext()
- .getRequestParameterValuesMap();
-
- if (HtmlRendererUtils.isDisabledOrReadOnly(uiComponent))
- return;
-
- if (paramValuesMap.containsKey(hiddenClientId))
- {
- String[] valuesInline = (String[]) paramValuesMap
- .get(hiddenClientId);
-
- if (valuesInline[0].trim().equals(""))
- {
- ((EditableValueHolder) uiComponent)
- .setSubmittedValue(new String[] {});
- }
- else
- {
- String[] reqValues = valuesInline[0].split(",");
- ((EditableValueHolder) uiComponent)
- .setSubmittedValue(reqValues);
- }
- }
- else
- {
- /* request parameter not found, nothing to decode - set submitted value to an empty array
- as we should get here only if the component is on a submitted form, is rendered
- and if the component is not readonly or has not been disabled.
-
- So in fact, there must be component value at this location, but for listboxes, comboboxes etc.
- the submitted value is not posted if no item is selected. */
- ((EditableValueHolder) uiComponent)
- .setSubmittedValue(new String[] {});
- }
- }
-
- public void encodeEnd(FacesContext facesContext, UIComponent uiComponent)
- throws IOException
- {
- RendererUtils.checkParamValidity(facesContext, uiComponent,
- HtmlSelectManyPicklist.class);
-
- HtmlSelectManyPicklist picklist = (HtmlSelectManyPicklist) uiComponent;
-
- String addButtonText = picklist.getAddButtonText();
- String removeButtonText = picklist.getRemoveButtonText();
- String addButtonStyle = picklist.getAddButtonStyle();
- String removeButtonStyle = picklist.getRemoveButtonStyle();
- String addButtonStyleClass = picklist.getAddButtonStyleClass();
- String removeButtonStyleClass = picklist.getRemoveButtonStyleClass();
-
- //Set the default values for addButtonText and removeButtonText
- if(addButtonText == null || addButtonText.length() == 0)
- addButtonText = ">";
-
- if(removeButtonText == null || removeButtonText.length() == 0)
- removeButtonText = "<";
-
- encodeJavascript(facesContext, uiComponent);
-
- String availableListClientId = uiComponent.getClientId(facesContext)
- + AVAILABLE_SUFFIX;
- String selectedListClientId = uiComponent.getClientId(facesContext)
- + SELECTED_SUFFIX;
- String hiddenFieldCliendId = uiComponent.getClientId(facesContext)
- + HIDDEN_SUFFIX;
-
- List selectItemList = RendererUtils
- .getSelectItemList((UISelectMany) uiComponent);
- Converter converter = HtmlRendererUtils
- .findUISelectManyConverterFailsafe(facesContext, uiComponent);
-
- Set lookupSet = HtmlRendererUtils.getSubmittedOrSelectedValuesAsSet(
- true, uiComponent, facesContext, converter);
-
- List selectItemsForSelectedValues = selectItemsForSelectedList(
- facesContext, uiComponent, selectItemList, converter, lookupSet);
- List selectItemsForAvailableList = selectItemsForAvailableList(
- facesContext, uiComponent, selectItemList,
- selectItemsForSelectedValues, converter);
-
- ResponseWriter writer = facesContext.getResponseWriter();
-
- writer.startElement(HTML.TABLE_ELEM, uiComponent);
- writer.startElement(HTML.TR_ELEM, uiComponent);
- writer.startElement(HTML.TD_ELEM, uiComponent);
-
- encodeSelect(facesContext, picklist, availableListClientId, isDisabled(
- facesContext, uiComponent), picklist.getSize(),
- selectItemsForAvailableList, converter);
-
- writer.endElement(HTML.TD_ELEM);
-
- // encode buttons
- writer.startElement(HTML.TD_ELEM, uiComponent);
-
- String javascriptAddToSelected = FUNCTION_ADD_TO_SELECTED + "('"
- + availableListClientId + "','" + selectedListClientId + "','"
- + hiddenFieldCliendId + "')";
- String javascriptRemoveFromSelected = FUNCTION_REMOVE_FROM_SELECTED
- + "('" + availableListClientId + "','" + selectedListClientId
- + "','" + hiddenFieldCliendId + "')";
-
- encodeSwapButton(facesContext, uiComponent, javascriptAddToSelected,
- addButtonText, addButtonStyle, addButtonStyleClass);
-
- writer.startElement(HTML.BR_ELEM, uiComponent);
- writer.endElement(HTML.BR_ELEM);
-
- encodeSwapButton(facesContext, uiComponent, javascriptRemoveFromSelected,
- removeButtonText, removeButtonStyle, removeButtonStyleClass);
-
- writer.endElement(HTML.TD_ELEM);
-
- // encode selected list
- writer.startElement(HTML.TD_ELEM, uiComponent);
-
- encodeSelect(facesContext, picklist, selectedListClientId, isDisabled(
- facesContext, uiComponent), picklist.getSize(),
- selectItemsForSelectedValues, converter);
-
- // hidden field with the selected values
- encodeHiddenField(facesContext, uiComponent, hiddenFieldCliendId,
- lookupSet);
-
- writer.endElement(HTML.TD_ELEM);
- writer.endElement(HTML.TR_ELEM);
- writer.endElement(HTML.TABLE_ELEM);
- }
-
- private void encodeJavascript(FacesContext facesContext,
- UIComponent uiComponent)
- {
- // AddResource takes care to add only one reference to the same script
- AddResource addResource = AddResourceFactory.getInstance(facesContext);
- addResource.addJavaScriptAtPosition(facesContext, AddResource.HEADER_BEGIN,
- HtmlPicklistRenderer.class, "picklist.js");
- }
-
- private void encodeSwapButton(FacesContext facesContext,
- UIComponent uiComponent, String javaScriptFunction,
- String text, String style, String styleClass)
- throws IOException
- {
- ResponseWriter writer = facesContext.getResponseWriter();
-
- writer.startElement(HTML.INPUT_ELEM, uiComponent);
- writer.writeAttribute(HTML.STYLE_ATTR, style, null);
- writer.writeAttribute(HTML.CLASS_ATTR, styleClass, null);
- writer.writeAttribute(HTML.TYPE_ATTR, HTML.INPUT_TYPE_BUTTON,
- JSFAttr.TYPE_ATTR);
- writer.writeAttribute(HTML.ONCLICK_ATTR, javaScriptFunction, null);
- writer.writeAttribute(HTML.VALUE_ATTR, text, null);
- writer.endElement(HTML.INPUT_ELEM);
- }
-
- private void encodeSelect(FacesContext facesContext,
- UIComponent uiComponent, String clientId, boolean disabled,
- int size, List selectItemsToDisplay, Converter converter)
- throws IOException
- {
- ResponseWriter writer = facesContext.getResponseWriter();
-
- writer.startElement(HTML.SELECT_ELEM, uiComponent);
- writer.writeAttribute(HTML.ID_ATTR, clientId, JSFAttr.ID_ATTR);
- writer.writeAttribute(HTML.NAME_ATTR, clientId, null);
-
- writer.writeAttribute(HTML.MULTIPLE_ATTR, "true", null);
-
- if (size == 0)
- {
- //No size given (Listbox) --> size is number of select items
- writer.writeAttribute(HTML.SIZE_ATTR, Integer
- .toString(selectItemsToDisplay.size()), null);
- }
- else
- {
- writer.writeAttribute(HTML.SIZE_ATTR, Integer.toString(size), null);
- }
- HtmlRendererUtils.renderHTMLAttributes(writer, uiComponent,
- HTML.SELECT_PASSTHROUGH_ATTRIBUTES_WITHOUT_DISABLED);
- if (disabled)
- {
- writer.writeAttribute(HTML.DISABLED_ATTR, Boolean.TRUE, null);
- }
-
- HtmlRendererUtils.renderSelectOptions(facesContext, uiComponent,
- converter, Collections.EMPTY_SET, selectItemsToDisplay);
-
- // bug #970747: force separate end tag
- writer.writeText("", null);
- writer.endElement(HTML.SELECT_ELEM);
- }
-
- private void encodeHiddenField(FacesContext facesContext,
- UIComponent uiComponent, String hiddenFieldCliendId, Set lookupSet)
- throws IOException
- {
- ResponseWriter writer = facesContext.getResponseWriter();
-
- writer.startElement(HTML.INPUT_ELEM, uiComponent);
- writer.writeAttribute(HTML.TYPE_ATTR, HTML.INPUT_TYPE_HIDDEN,
- JSFAttr.TYPE_ATTR);
- writer.writeAttribute(HTML.ID_ATTR, hiddenFieldCliendId,
- JSFAttr.ID_ATTR);
- writer.writeAttribute(HTML.NAME_ATTR, hiddenFieldCliendId, null);
-
- StringBuffer sb = new StringBuffer();
- int n = 0;
- for (Iterator i = lookupSet.iterator(); i.hasNext();)
- {
- if (n > 0)
- {
- sb.append(",");
- }
- String value = (String) i.next();
- sb.append(value);
- n++;
- }
-
- writer.writeAttribute(HTML.VALUE_ATTR, sb.toString(), null);
- writer.endElement(HTML.INPUT_ELEM);
-
- }
-
- private List selectItemsForSelectedList(FacesContext facesContext,
- UIComponent uiComponent, List selectItemList, Converter converter,
- Set lookupSet)
- {
- List selectItemForSelectedValues = new ArrayList(lookupSet.size());
-
- for (Iterator i = selectItemList.iterator(); i.hasNext();)
- {
- SelectItem selectItem = (SelectItem) i.next();
- String itemStrValue = RendererUtils.getConvertedStringValue(facesContext, uiComponent,
- converter, selectItem);
-
-
- for (Iterator i2 = lookupSet.iterator(); i2.hasNext();)
- {
- Object value = i2.next();
- if (value.equals(itemStrValue))
- {
- selectItemForSelectedValues.add(selectItem);
- }
- }
- }
-
- return selectItemForSelectedValues;
- }
-
- private List selectItemsForAvailableList(FacesContext facesContext,
- UIComponent uiComponent, List selectItemList,
- List selectItemsForSelectedList, Converter converter)
- {
-
- return new ArrayList(CollectionUtils.subtract(selectItemList,
- selectItemsForSelectedList));
- }
-
-}
+/*
+ * 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.picklist;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.faces.component.EditableValueHolder;
+import javax.faces.component.UIComponent;
+import javax.faces.component.UISelectMany;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+import javax.faces.convert.Converter;
+import javax.faces.model.SelectItem;
+
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.myfaces.renderkit.html.util.AddResource;
+import org.apache.myfaces.renderkit.html.util.AddResourceFactory;
+import org.apache.myfaces.shared_tomahawk.renderkit.html.HTML;
+import org.apache.myfaces.shared_tomahawk.renderkit.JSFAttr;
+import org.apache.myfaces.shared_tomahawk.renderkit.RendererUtils;
+import org.apache.myfaces.shared_tomahawk.renderkit.html.HtmlRendererUtils;
+import org.apache.myfaces.shared_tomahawk.renderkit.html.HtmlListboxRendererBase;
+
+/**
+ *
+ * @JSFRenderer
+ * renderKitId = "HTML_BASIC"
+ * family = "javax.faces.SelectMany"
+ * type = "org.apache.myfaces.PicklistRenderer"
+ *
+ * @author Bruno Aranda (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+public class HtmlPicklistRenderer extends HtmlListboxRendererBase
+{
+
+ private static final String FUNCTION_ADD_TO_SELECTED = "myfaces_picklist_addToSelected";
+ private static final String FUNCTION_REMOVE_FROM_SELECTED = "myfaces_picklist_removeFromSelected";
+
+ private static final String AVAILABLE_SUFFIX = "_AVAILABLE";
+ private static final String SELECTED_SUFFIX = "_SELECTED";
+ private static final String HIDDEN_SUFFIX = "_HIDDEN";
+
+ public void decode(FacesContext facesContext, UIComponent uiComponent)
+ {
+ RendererUtils.checkParamValidity(facesContext, uiComponent, null);
+
+ if (!(uiComponent instanceof EditableValueHolder))
+ {
+ throw new IllegalArgumentException("Component "
+ + uiComponent.getClientId(facesContext)
+ + " is not an EditableValueHolder");
+ }
+
+ String hiddenClientId = uiComponent.getClientId(facesContext)
+ + HIDDEN_SUFFIX;
+
+ Map paramValuesMap = facesContext.getExternalContext()
+ .getRequestParameterValuesMap();
+
+ if (HtmlRendererUtils.isDisabledOrReadOnly(uiComponent))
+ return;
+
+ if (paramValuesMap.containsKey(hiddenClientId))
+ {
+ String[] valuesInline = (String[]) paramValuesMap
+ .get(hiddenClientId);
+
+ if (valuesInline[0].trim().equals(""))
+ {
+ ((EditableValueHolder) uiComponent)
+ .setSubmittedValue(new String[] {});
+ }
+ else
+ {
+ String[] reqValues = valuesInline[0].split(",");
+ ((EditableValueHolder) uiComponent)
+ .setSubmittedValue(reqValues);
+ }
+ }
+ else
+ {
+ /* request parameter not found, nothing to decode - set submitted value to an empty array
+ as we should get here only if the component is on a submitted form, is rendered
+ and if the component is not readonly or has not been disabled.
+
+ So in fact, there must be component value at this location, but for listboxes, comboboxes etc.
+ the submitted value is not posted if no item is selected. */
+ ((EditableValueHolder) uiComponent)
+ .setSubmittedValue(new String[] {});
+ }
+ }
+
+ public void encodeEnd(FacesContext facesContext, UIComponent uiComponent)
+ throws IOException
+ {
+ RendererUtils.checkParamValidity(facesContext, uiComponent,
+ HtmlSelectManyPicklist.class);
+
+ HtmlSelectManyPicklist picklist = (HtmlSelectManyPicklist) uiComponent;
+
+ String addButtonText = picklist.getAddButtonText();
+ String removeButtonText = picklist.getRemoveButtonText();
+ String addButtonStyle = picklist.getAddButtonStyle();
+ String removeButtonStyle = picklist.getRemoveButtonStyle();
+ String addButtonStyleClass = picklist.getAddButtonStyleClass();
+ String removeButtonStyleClass = picklist.getRemoveButtonStyleClass();
+
+ //Set the default values for addButtonText and removeButtonText
+ if(addButtonText == null || addButtonText.length() == 0)
+ addButtonText = ">";
+
+ if(removeButtonText == null || removeButtonText.length() == 0)
+ removeButtonText = "<";
+
+ encodeJavascript(facesContext, uiComponent);
+
+ String availableListClientId = uiComponent.getClientId(facesContext)
+ + AVAILABLE_SUFFIX;
+ String selectedListClientId = uiComponent.getClientId(facesContext)
+ + SELECTED_SUFFIX;
+ String hiddenFieldCliendId = uiComponent.getClientId(facesContext)
+ + HIDDEN_SUFFIX;
+
+ List selectItemList = RendererUtils
+ .getSelectItemList((UISelectMany) uiComponent);
+ Converter converter = HtmlRendererUtils
+ .findUISelectManyConverterFailsafe(facesContext, uiComponent);
+
+ Set lookupSet = HtmlRendererUtils.getSubmittedOrSelectedValuesAsSet(
+ true, uiComponent, facesContext, converter);
+
+ List selectItemsForSelectedValues = selectItemsForSelectedList(
+ facesContext, uiComponent, selectItemList, converter, lookupSet);
+ List selectItemsForAvailableList = selectItemsForAvailableList(
+ facesContext, uiComponent, selectItemList,
+ selectItemsForSelectedValues, converter);
+
+ ResponseWriter writer = facesContext.getResponseWriter();
+
+ writer.startElement(HTML.TABLE_ELEM, uiComponent);
+ writer.startElement(HTML.TR_ELEM, uiComponent);
+ writer.startElement(HTML.TD_ELEM, uiComponent);
+
+ encodeSelect(facesContext, picklist, availableListClientId, isDisabled(
+ facesContext, uiComponent), picklist.getSize(),
+ selectItemsForAvailableList, converter);
+
+ writer.endElement(HTML.TD_ELEM);
+
+ // encode buttons
+ writer.startElement(HTML.TD_ELEM, uiComponent);
+
+ String javascriptAddToSelected = FUNCTION_ADD_TO_SELECTED + "('"
+ + availableListClientId + "','" + selectedListClientId + "','"
+ + hiddenFieldCliendId + "')";
+ String javascriptRemoveFromSelected = FUNCTION_REMOVE_FROM_SELECTED
+ + "('" + availableListClientId + "','" + selectedListClientId
+ + "','" + hiddenFieldCliendId + "')";
+
+ encodeSwapButton(facesContext, uiComponent, javascriptAddToSelected,
+ addButtonText, addButtonStyle, addButtonStyleClass);
+
+ writer.startElement(HTML.BR_ELEM, uiComponent);
+ writer.endElement(HTML.BR_ELEM);
+
+ encodeSwapButton(facesContext, uiComponent, javascriptRemoveFromSelected,
+ removeButtonText, removeButtonStyle, removeButtonStyleClass);
+
+ writer.endElement(HTML.TD_ELEM);
+
+ // encode selected list
+ writer.startElement(HTML.TD_ELEM, uiComponent);
+
+ encodeSelect(facesContext, picklist, selectedListClientId, isDisabled(
+ facesContext, uiComponent), picklist.getSize(),
+ selectItemsForSelectedValues, converter);
+
+ // hidden field with the selected values
+ encodeHiddenField(facesContext, uiComponent, hiddenFieldCliendId,
+ lookupSet);
+
+ writer.endElement(HTML.TD_ELEM);
+ writer.endElement(HTML.TR_ELEM);
+ writer.endElement(HTML.TABLE_ELEM);
+ }
+
+ private void encodeJavascript(FacesContext facesContext,
+ UIComponent uiComponent)
+ {
+ // AddResource takes care to add only one reference to the same script
+ AddResource addResource = AddResourceFactory.getInstance(facesContext);
+ addResource.addJavaScriptAtPosition(facesContext, AddResource.HEADER_BEGIN,
+ HtmlPicklistRenderer.class, "picklist.js");
+ }
+
+ private void encodeSwapButton(FacesContext facesContext,
+ UIComponent uiComponent, String javaScriptFunction,
+ String text, String style, String styleClass)
+ throws IOException
+ {
+ ResponseWriter writer = facesContext.getResponseWriter();
+
+ writer.startElement(HTML.INPUT_ELEM, uiComponent);
+ writer.writeAttribute(HTML.STYLE_ATTR, style, null);
+ writer.writeAttribute(HTML.CLASS_ATTR, styleClass, null);
+ writer.writeAttribute(HTML.TYPE_ATTR, HTML.INPUT_TYPE_BUTTON,
+ JSFAttr.TYPE_ATTR);
+ writer.writeAttribute(HTML.ONCLICK_ATTR, javaScriptFunction, null);
+ writer.writeAttribute(HTML.VALUE_ATTR, text, null);
+ writer.endElement(HTML.INPUT_ELEM);
+ }
+
+ private void encodeSelect(FacesContext facesContext,
+ UIComponent uiComponent, String clientId, boolean disabled,
+ int size, List selectItemsToDisplay, Converter converter)
+ throws IOException
+ {
+ ResponseWriter writer = facesContext.getResponseWriter();
+
+ writer.startElement(HTML.SELECT_ELEM, uiComponent);
+ writer.writeAttribute(HTML.ID_ATTR, clientId, JSFAttr.ID_ATTR);
+ writer.writeAttribute(HTML.NAME_ATTR, clientId, null);
+
+ writer.writeAttribute(HTML.MULTIPLE_ATTR, "true", null);
+
+ if (size == 0)
+ {
+ //No size given (Listbox) --> size is number of select items
+ writer.writeAttribute(HTML.SIZE_ATTR, Integer
+ .toString(selectItemsToDisplay.size()), null);
+ }
+ else
+ {
+ writer.writeAttribute(HTML.SIZE_ATTR, Integer.toString(size), null);
+ }
+ HtmlRendererUtils.renderHTMLAttributes(writer, uiComponent,
+ HTML.SELECT_PASSTHROUGH_ATTRIBUTES_WITHOUT_DISABLED);
+ if (disabled)
+ {
+ writer.writeAttribute(HTML.DISABLED_ATTR, Boolean.TRUE, null);
+ }
+
+ HtmlRendererUtils.renderSelectOptions(facesContext, uiComponent,
+ converter, Collections.EMPTY_SET, selectItemsToDisplay);
+
+ // bug #970747: force separate end tag
+ writer.writeText("", null);
+ writer.endElement(HTML.SELECT_ELEM);
+ }
+
+ private void encodeHiddenField(FacesContext facesContext,
+ UIComponent uiComponent, String hiddenFieldCliendId, Set lookupSet)
+ throws IOException
+ {
+ ResponseWriter writer = facesContext.getResponseWriter();
+
+ writer.startElement(HTML.INPUT_ELEM, uiComponent);
+ writer.writeAttribute(HTML.TYPE_ATTR, HTML.INPUT_TYPE_HIDDEN,
+ JSFAttr.TYPE_ATTR);
+ writer.writeAttribute(HTML.ID_ATTR, hiddenFieldCliendId,
+ JSFAttr.ID_ATTR);
+ writer.writeAttribute(HTML.NAME_ATTR, hiddenFieldCliendId, null);
+
+ StringBuffer sb = new StringBuffer();
+ int n = 0;
+ for (Iterator i = lookupSet.iterator(); i.hasNext();)
+ {
+ if (n > 0)
+ {
+ sb.append(",");
+ }
+ String value = (String) i.next();
+ sb.append(value);
+ n++;
+ }
+
+ writer.writeAttribute(HTML.VALUE_ATTR, sb.toString(), null);
+ writer.endElement(HTML.INPUT_ELEM);
+
+ }
+
+ private List selectItemsForSelectedList(FacesContext facesContext,
+ UIComponent uiComponent, List selectItemList, Converter converter,
+ Set lookupSet)
+ {
+ List selectItemForSelectedValues = new ArrayList(lookupSet.size());
+
+ for (Iterator i = selectItemList.iterator(); i.hasNext();)
+ {
+ SelectItem selectItem = (SelectItem) i.next();
+ String itemStrValue = RendererUtils.getConvertedStringValue(facesContext, uiComponent,
+ converter, selectItem);
+
+
+ for (Iterator i2 = lookupSet.iterator(); i2.hasNext();)
+ {
+ Object value = i2.next();
+ if (value.equals(itemStrValue))
+ {
+ selectItemForSelectedValues.add(selectItem);
+ }
+ }
+ }
+
+ return selectItemForSelectedValues;
+ }
+
+ private List selectItemsForAvailableList(FacesContext facesContext,
+ UIComponent uiComponent, List selectItemList,
+ List selectItemsForSelectedList, Converter converter)
+ {
+
+ return new ArrayList(CollectionUtils.subtract(selectItemList,
+ selectItemsForSelectedList));
+ }
+
+}
Propchange: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/picklist/HtmlPicklistRenderer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/AbstractCompactScheduleRenderer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/AbstractScheduleRenderer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/DefaultScheduleEntryRenderer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/ScheduleCompactMonthRenderer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/ScheduleCompactWeekRenderer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/ScheduleDelegatingRenderer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/ScheduleDetailedDayRenderer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/ScheduleEntryRenderer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/model/HalfHourInterval.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/model/Interval.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: 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=673836&r1=673835&r2=673836&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/selectOneRow/AbstractSelectOneRow.java (original)
+++ myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/selectOneRow/AbstractSelectOneRow.java Thu Jul 3 15:03:29 2008
@@ -1,105 +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();
-
-}
+/*
+ * 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();
+
+}
Propchange: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/selectOneRow/AbstractSelectOneRow.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: 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=673836&r1=673835&r2=673836&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/selectOneRow/SelectOneRowRenderer.java (original)
+++ myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/selectOneRow/SelectOneRowRenderer.java Thu Jul 3 15:03:29 2008
@@ -1,141 +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);
- }
- }
- }
-}
+/*
+ * 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);
+ }
+ }
+ }
+}
Propchange: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/selectOneRow/SelectOneRowRenderer.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/subform/AbstractSubForm.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/subform/AbstractSubForm.java?rev=673836&r1=673835&r2=673836&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/subform/AbstractSubForm.java (original)
+++ myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/subform/AbstractSubForm.java Thu Jul 3 15:03:29 2008
@@ -1,303 +1,303 @@
-/*
- * 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.subform;
-
-import java.util.Iterator;
-import java.util.List;
-
-import javax.faces.component.EditableValueHolder;
-import javax.faces.component.NamingContainer;
-import javax.faces.component.UIComponent;
-import javax.faces.component.UIComponentBase;
-import javax.faces.context.FacesContext;
-import javax.faces.event.ActionEvent;
-import javax.faces.event.FacesEvent;
-import javax.faces.event.PhaseId;
-
-import org.apache.myfaces.shared_tomahawk.renderkit.RendererUtils;
-
-/**
- * A SubForm which will allow for partial validation
- * and model update.
- * <p>
- * A subform to an existing form. Inputs in this form will only be
- * validated and updated, if a t:commandButton or t:commandLink
- * has been clicked with an actionFor attribute which references
- * the client-id of this subform. Optionally, the validation will
- * trigger if a commandButton or commandLink embedded in this
- * subform has been clicked, except if this command is a
- * t:commandButton or t:commandLink with an actionFor attribute
- * which doesn't reference the client-id of this subform.
- * </p>
- * <p>
- * Components will be validated and updated only if
- * either a child-component of this form caused
- * the submit of the form, or an extended commandLink
- * or commandButton with the actionFor attribute set
- * to the client-id of this component was used.
- * </p>
- * <p>
- * You can have several comma-separated entries in
- * the actionFor-attribute - with this it's possible to
- * validate and update more than one subForm at once.
- * </p>
- *
- * @JSFComponent
- * name = "t:subform"
- * class = "org.apache.myfaces.custom.subform.SubForm"
- * tagClass = "org.apache.myfaces.custom.subform.SubFormTag"
- * implements = "javax.faces.component.NamingContainer"
- *
- * @author Gerald Muellan
- * @author Martin Marinschek
- * Date: 19.01.2006
- * Time: 13:58:18
- */
-public abstract class AbstractSubForm extends UIComponentBase
- implements NamingContainer
-{
-
- public static final String COMPONENT_TYPE = "org.apache.myfaces.SubForm";
- public static final String DEFAULT_RENDERER_TYPE = "org.apache.myfaces.SubForm";
- public static final String COMPONENT_FAMILY = "org.apache.myfaces.SubForm";
-
- private static final String PARTIAL_ENABLED = "org.apache.myfaces.IsPartialPhaseExecutionEnabled";
- private boolean _submitted;
-
- public AbstractSubForm()
- {
- super.setRendererType(DEFAULT_RENDERER_TYPE);
- }
-
- public String getFamily()
- {
- return COMPONENT_FAMILY;
- }
-
- public boolean isSubmitted()
- {
- return _submitted;
- }
-
- public void setSubmitted(boolean submitted)
- {
- _submitted = submitted;
- }
-
- /**
- * true|false - set to false if you submit other subforms and would like to
- * have your subform reflecting any model update. Default: true
- *
- * @JSFProperty
- * @return
- */
- public abstract Boolean getPreserveSubmittedValues();
-
-
- public void processDecodes(FacesContext context)
- {
- super.processDecodes(context);
- if (!isRendered()) return;
-
- if (!_submitted && Boolean.FALSE.equals(getPreserveSubmittedValues()))
- {
- // didn't find any better way as we do not know if we are submitted before the
- // decode phase, but then all the other components have the submitted value
- // set already.
- // so lets reset them again ... boring hack.
- resetSubmittedValues(this, context);
- }
- }
-
- public void processValidators(FacesContext context)
- {
- if (context == null) throw new NullPointerException("context");
- if (!isRendered()) return;
-
- boolean partialEnabled = isPartialEnabled(context, PhaseId.PROCESS_VALIDATIONS);
-
- if(partialEnabled || (_submitted && isEmptyList(context)))
- {
- for (Iterator it = getFacetsAndChildren(); it.hasNext(); )
- {
- UIComponent childOrFacet = (UIComponent)it.next();
- childOrFacet.processValidators(context);
- }
- }
- else
- {
- processSubFormValidators(this,context);
- }
- }
-
- public void processUpdates(FacesContext context)
- {
- if (context == null) throw new NullPointerException("context");
- if (!isRendered()) return;
-
- boolean partialEnabled = isPartialEnabled(context,PhaseId.UPDATE_MODEL_VALUES);
-
- if(partialEnabled || _submitted)
- {
- for (Iterator it = getFacetsAndChildren(); it.hasNext(); )
- {
- UIComponent childOrFacet = (UIComponent)it.next();
- childOrFacet.processUpdates(context);
- }
- }
- else
- {
- processSubFormUpdates(this,context);
- }
- }
-
- private static void resetSubmittedValues(UIComponent comp, FacesContext context)
- {
- for (Iterator it = comp.getFacetsAndChildren(); it.hasNext(); )
- {
- UIComponent childOrFacet = (UIComponent)it.next();
- if (childOrFacet instanceof AbstractSubForm)
- {
- // we are not responsible for this subForm, are we?
- continue;
- }
-
- if (childOrFacet instanceof EditableValueHolder)
- {
- ((EditableValueHolder) childOrFacet).setSubmittedValue(null);
- }
-
- resetSubmittedValues(childOrFacet, context);
- }
- }
-
- private static void processSubFormUpdates(UIComponent comp, FacesContext context)
- {
- for (Iterator it = comp.getFacetsAndChildren(); it.hasNext(); )
- {
- UIComponent childOrFacet = (UIComponent)it.next();
-
- if(childOrFacet instanceof AbstractSubForm)
- {
- childOrFacet.processUpdates(context);
- }
- else
- {
- processSubFormUpdates(childOrFacet, context);
- }
- }
- }
-
- private static void processSubFormValidators(UIComponent comp, FacesContext context)
- {
- for (Iterator it = comp.getFacetsAndChildren(); it.hasNext(); )
- {
- UIComponent childOrFacet = (UIComponent)it.next();
-
- if(childOrFacet instanceof AbstractSubForm)
- {
- childOrFacet.processValidators(context);
- }
- else
- {
- processSubFormValidators(childOrFacet, context);
- }
- }
- }
-
- public void queueEvent(FacesEvent event)
- {
- if(event instanceof ActionEvent)
- {
- _submitted = true;
- }
-
- // This idea is taken from ADF faces - my approach of checking for instanceof ActionEvent
- // didn't go as far as necessary for dataTables.
- // In the dataTable case, the ActionEvent is wrapped in an EventWrapper
- //
- // I still believe the second part of the if condition is a hack:
- // If the event is being queued for anything *after* APPLY_REQUEST_VALUES,
- // then this subform is active - IMHO there might be other events not relating
- // to the action system which are queued after this phase.
- if (PhaseId.APPLY_REQUEST_VALUES.compareTo(event.getPhaseId()) < 0)
- {
- setSubmitted(true);
- }
-
- super.queueEvent(event);
- }
-
- protected boolean isEmptyList(FacesContext context)
- {
- //get the list of (parent) client-ids for which a validation/model update should be performed
- List li = (List) context.getExternalContext().getRequestMap().get(
- RendererUtils.ACTION_FOR_LIST);
-
- return li==null || li.size()==0;
- }
-
- /**Sets up information if this component is included in
- * the group of components which are associated with the current action.
- *
- * @param context
- * @return true if there has been a change by this setup which has to be undone after the phase finishes.
- */
- protected boolean isPartialEnabled(FacesContext context, PhaseId phaseId)
- {
- //we want to execute validation (and model update) only
- //if certain conditions are met
- //especially, we want to switch validation/update on/off depending on
- //the attribute "actionFor" of a MyFaces extended button or link
- //if you use commandButtons which don't set these
- //request parameters, this won't cause any adverse effects
-
- boolean partialEnabled = false;
-
- //get the list of (parent) client-ids for which a validation/model update should be performed
- List li = (List) context.getExternalContext().getRequestMap().get(
- RendererUtils.ACTION_FOR_LIST);
-
- //if there is a list, check if the current client id
- //matches an entry of the list
- if(li != null && li.contains(getClientId(context)))
- {
- if(!context.getExternalContext().getRequestMap().containsKey(PARTIAL_ENABLED))
- {
- partialEnabled=true;
- }
- }
-
- if(partialEnabled)
- {
- //get the list of phases which should be executed
- List phaseList = (List) context.getExternalContext().getRequestMap().get(
- RendererUtils.ACTION_FOR_PHASE_LIST);
-
- if(phaseList != null && !phaseList.isEmpty() && !phaseList.contains(phaseId))
- {
- partialEnabled=false;
- }
- }
-
- return partialEnabled;
- }
-
-
-}
+/*
+ * 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.subform;
+
+import java.util.Iterator;
+import java.util.List;
+
+import javax.faces.component.EditableValueHolder;
+import javax.faces.component.NamingContainer;
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIComponentBase;
+import javax.faces.context.FacesContext;
+import javax.faces.event.ActionEvent;
+import javax.faces.event.FacesEvent;
+import javax.faces.event.PhaseId;
+
+import org.apache.myfaces.shared_tomahawk.renderkit.RendererUtils;
+
+/**
+ * A SubForm which will allow for partial validation
+ * and model update.
+ * <p>
+ * A subform to an existing form. Inputs in this form will only be
+ * validated and updated, if a t:commandButton or t:commandLink
+ * has been clicked with an actionFor attribute which references
+ * the client-id of this subform. Optionally, the validation will
+ * trigger if a commandButton or commandLink embedded in this
+ * subform has been clicked, except if this command is a
+ * t:commandButton or t:commandLink with an actionFor attribute
+ * which doesn't reference the client-id of this subform.
+ * </p>
+ * <p>
+ * Components will be validated and updated only if
+ * either a child-component of this form caused
+ * the submit of the form, or an extended commandLink
+ * or commandButton with the actionFor attribute set
+ * to the client-id of this component was used.
+ * </p>
+ * <p>
+ * You can have several comma-separated entries in
+ * the actionFor-attribute - with this it's possible to
+ * validate and update more than one subForm at once.
+ * </p>
+ *
+ * @JSFComponent
+ * name = "t:subform"
+ * class = "org.apache.myfaces.custom.subform.SubForm"
+ * tagClass = "org.apache.myfaces.custom.subform.SubFormTag"
+ * implements = "javax.faces.component.NamingContainer"
+ *
+ * @author Gerald Muellan
+ * @author Martin Marinschek
+ * Date: 19.01.2006
+ * Time: 13:58:18
+ */
+public abstract class AbstractSubForm extends UIComponentBase
+ implements NamingContainer
+{
+
+ public static final String COMPONENT_TYPE = "org.apache.myfaces.SubForm";
+ public static final String DEFAULT_RENDERER_TYPE = "org.apache.myfaces.SubForm";
+ public static final String COMPONENT_FAMILY = "org.apache.myfaces.SubForm";
+
+ private static final String PARTIAL_ENABLED = "org.apache.myfaces.IsPartialPhaseExecutionEnabled";
+ private boolean _submitted;
+
+ public AbstractSubForm()
+ {
+ super.setRendererType(DEFAULT_RENDERER_TYPE);
+ }
+
+ public String getFamily()
+ {
+ return COMPONENT_FAMILY;
+ }
+
+ public boolean isSubmitted()
+ {
+ return _submitted;
+ }
+
+ public void setSubmitted(boolean submitted)
+ {
+ _submitted = submitted;
+ }
+
+ /**
+ * true|false - set to false if you submit other subforms and would like to
+ * have your subform reflecting any model update. Default: true
+ *
+ * @JSFProperty
+ * @return
+ */
+ public abstract Boolean getPreserveSubmittedValues();
+
+
+ public void processDecodes(FacesContext context)
+ {
+ super.processDecodes(context);
+ if (!isRendered()) return;
+
+ if (!_submitted && Boolean.FALSE.equals(getPreserveSubmittedValues()))
+ {
+ // didn't find any better way as we do not know if we are submitted before the
+ // decode phase, but then all the other components have the submitted value
+ // set already.
+ // so lets reset them again ... boring hack.
+ resetSubmittedValues(this, context);
+ }
+ }
+
+ public void processValidators(FacesContext context)
+ {
+ if (context == null) throw new NullPointerException("context");
+ if (!isRendered()) return;
+
+ boolean partialEnabled = isPartialEnabled(context, PhaseId.PROCESS_VALIDATIONS);
+
+ if(partialEnabled || (_submitted && isEmptyList(context)))
+ {
+ for (Iterator it = getFacetsAndChildren(); it.hasNext(); )
+ {
+ UIComponent childOrFacet = (UIComponent)it.next();
+ childOrFacet.processValidators(context);
+ }
+ }
+ else
+ {
+ processSubFormValidators(this,context);
+ }
+ }
+
+ public void processUpdates(FacesContext context)
+ {
+ if (context == null) throw new NullPointerException("context");
+ if (!isRendered()) return;
+
+ boolean partialEnabled = isPartialEnabled(context,PhaseId.UPDATE_MODEL_VALUES);
+
+ if(partialEnabled || _submitted)
+ {
+ for (Iterator it = getFacetsAndChildren(); it.hasNext(); )
+ {
+ UIComponent childOrFacet = (UIComponent)it.next();
+ childOrFacet.processUpdates(context);
+ }
+ }
+ else
+ {
+ processSubFormUpdates(this,context);
+ }
+ }
+
+ private static void resetSubmittedValues(UIComponent comp, FacesContext context)
+ {
+ for (Iterator it = comp.getFacetsAndChildren(); it.hasNext(); )
+ {
+ UIComponent childOrFacet = (UIComponent)it.next();
+ if (childOrFacet instanceof AbstractSubForm)
+ {
+ // we are not responsible for this subForm, are we?
+ continue;
+ }
+
+ if (childOrFacet instanceof EditableValueHolder)
+ {
+ ((EditableValueHolder) childOrFacet).setSubmittedValue(null);
+ }
+
+ resetSubmittedValues(childOrFacet, context);
+ }
+ }
+
+ private static void processSubFormUpdates(UIComponent comp, FacesContext context)
+ {
+ for (Iterator it = comp.getFacetsAndChildren(); it.hasNext(); )
+ {
+ UIComponent childOrFacet = (UIComponent)it.next();
+
+ if(childOrFacet instanceof AbstractSubForm)
+ {
+ childOrFacet.processUpdates(context);
+ }
+ else
+ {
+ processSubFormUpdates(childOrFacet, context);
+ }
+ }
+ }
+
+ private static void processSubFormValidators(UIComponent comp, FacesContext context)
+ {
+ for (Iterator it = comp.getFacetsAndChildren(); it.hasNext(); )
+ {
+ UIComponent childOrFacet = (UIComponent)it.next();
+
+ if(childOrFacet instanceof AbstractSubForm)
+ {
+ childOrFacet.processValidators(context);
+ }
+ else
+ {
+ processSubFormValidators(childOrFacet, context);
+ }
+ }
+ }
+
+ public void queueEvent(FacesEvent event)
+ {
+ if(event instanceof ActionEvent)
+ {
+ _submitted = true;
+ }
+
+ // This idea is taken from ADF faces - my approach of checking for instanceof ActionEvent
+ // didn't go as far as necessary for dataTables.
+ // In the dataTable case, the ActionEvent is wrapped in an EventWrapper
+ //
+ // I still believe the second part of the if condition is a hack:
+ // If the event is being queued for anything *after* APPLY_REQUEST_VALUES,
+ // then this subform is active - IMHO there might be other events not relating
+ // to the action system which are queued after this phase.
+ if (PhaseId.APPLY_REQUEST_VALUES.compareTo(event.getPhaseId()) < 0)
+ {
+ setSubmitted(true);
+ }
+
+ super.queueEvent(event);
+ }
+
+ protected boolean isEmptyList(FacesContext context)
+ {
+ //get the list of (parent) client-ids for which a validation/model update should be performed
+ List li = (List) context.getExternalContext().getRequestMap().get(
+ RendererUtils.ACTION_FOR_LIST);
+
+ return li==null || li.size()==0;
+ }
+
+ /**Sets up information if this component is included in
+ * the group of components which are associated with the current action.
+ *
+ * @param context
+ * @return true if there has been a change by this setup which has to be undone after the phase finishes.
+ */
+ protected boolean isPartialEnabled(FacesContext context, PhaseId phaseId)
+ {
+ //we want to execute validation (and model update) only
+ //if certain conditions are met
+ //especially, we want to switch validation/update on/off depending on
+ //the attribute "actionFor" of a MyFaces extended button or link
+ //if you use commandButtons which don't set these
+ //request parameters, this won't cause any adverse effects
+
+ boolean partialEnabled = false;
+
+ //get the list of (parent) client-ids for which a validation/model update should be performed
+ List li = (List) context.getExternalContext().getRequestMap().get(
+ RendererUtils.ACTION_FOR_LIST);
+
+ //if there is a list, check if the current client id
+ //matches an entry of the list
+ if(li != null && li.contains(getClientId(context)))
+ {
+ if(!context.getExternalContext().getRequestMap().containsKey(PARTIAL_ENABLED))
+ {
+ partialEnabled=true;
+ }
+ }
+
+ if(partialEnabled)
+ {
+ //get the list of phases which should be executed
+ List phaseList = (List) context.getExternalContext().getRequestMap().get(
+ RendererUtils.ACTION_FOR_PHASE_LIST);
+
+ if(phaseList != null && !phaseList.isEmpty() && !phaseList.contains(phaseId))
+ {
+ partialEnabled=false;
+ }
+ }
+
+ return partialEnabled;
+ }
+
+
+}
Propchange: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/subform/AbstractSubForm.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/subform/SubFormRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/subform/SubFormRenderer.java?rev=673836&r1=673835&r2=673836&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/subform/SubFormRenderer.java (original)
+++ myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/subform/SubFormRenderer.java Thu Jul 3 15:03:29 2008
@@ -1,103 +1,103 @@
-/*
- * 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.subform;
-
-import org.apache.myfaces.shared_tomahawk.renderkit.RendererUtils;
-import org.apache.myfaces.shared_tomahawk.renderkit.html.HTML;
-import org.apache.myfaces.shared_tomahawk.renderkit.html.HtmlRenderer;
-import org.apache.myfaces.shared_tomahawk.renderkit.html.HtmlRendererUtils;
-import org.apache.myfaces.shared_tomahawk.renderkit.html.util.FormInfo;
-
-import javax.faces.component.UIComponent;
-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.SubForm"
- * type = "org.apache.myfaces.SubForm"
- *
- * @author Gerald Muellan
- * Date: 19.01.2006
- * Time: 14:01:35
- */
-public class SubFormRenderer extends HtmlRenderer
-{
- private static final String SUBMIT_FUNCTION_SUFFIX = "_submit";
- private static final String HIDDEN_PARAM_NAME = "org.apache.myfaces.custom.subform.submittedId";
-
-
- public void encodeBegin(FacesContext context, UIComponent component) throws IOException
- {
- super.encodeBegin(context, component);
-
- ResponseWriter writer = context.getResponseWriter();
-
- HtmlRendererUtils.writePrettyLineSeparator(context);
- writer.startElement(HTML.SCRIPT_ELEM, null);
- writer.writeAttribute(org.apache.myfaces.shared_tomahawk.renderkit.html.HTML.SCRIPT_TYPE_ATTR, org.apache.myfaces.shared_tomahawk.renderkit.html.HTML.SCRIPT_TYPE_TEXT_JAVASCRIPT, null);
-
- FormInfo parentFormInfo = RendererUtils.findNestingForm(component,context);
- if(parentFormInfo!=null)
- {
- writer.writeText(createPartialSubmitJS(component.getId(), parentFormInfo.getFormName()), null);
- }
-
- writer.endElement(org.apache.myfaces.shared_tomahawk.renderkit.html.HTML.SCRIPT_ELEM);
- HtmlRendererUtils.writePrettyLineSeparator(context);
- }
-
-
- public void decode(FacesContext context, UIComponent component)
- {
- super.decode(context, component);
-
- Map paramValuesMap = context.getExternalContext().getRequestParameterMap();
- String reqValue = (String) paramValuesMap.get(HIDDEN_PARAM_NAME);
- if (reqValue != null && component.getId().equals(reqValue))
- {
- ((SubForm) component).setSubmitted(true);
- }
- }
-
-
- protected String createPartialSubmitJS(String subFormId, String parentFormClientId)
- {
- StringBuffer script = new StringBuffer();
- script.append("function ");
- script.append(subFormId).append(SUBMIT_FUNCTION_SUFFIX + "()");
- script.append(" {\n");
- script.append("var form = document.forms['").append(parentFormClientId).append("'];\n");
- script.append("var el = document.createElement(\"input\");\n");
- script.append("el.type = \"hidden\";\n");
- script.append("el.name = \"" + HIDDEN_PARAM_NAME + "\";\n");
- script.append("el.value = \"").append(subFormId).append("\";\n");
- script.append("form.appendChild(el);\n");
- script.append("form.submit();\n");
- script.append("}\n");
-
- return script.toString();
- }
-
-}
+/*
+ * 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.subform;
+
+import org.apache.myfaces.shared_tomahawk.renderkit.RendererUtils;
+import org.apache.myfaces.shared_tomahawk.renderkit.html.HTML;
+import org.apache.myfaces.shared_tomahawk.renderkit.html.HtmlRenderer;
+import org.apache.myfaces.shared_tomahawk.renderkit.html.HtmlRendererUtils;
+import org.apache.myfaces.shared_tomahawk.renderkit.html.util.FormInfo;
+
+import javax.faces.component.UIComponent;
+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.SubForm"
+ * type = "org.apache.myfaces.SubForm"
+ *
+ * @author Gerald Muellan
+ * Date: 19.01.2006
+ * Time: 14:01:35
+ */
+public class SubFormRenderer extends HtmlRenderer
+{
+ private static final String SUBMIT_FUNCTION_SUFFIX = "_submit";
+ private static final String HIDDEN_PARAM_NAME = "org.apache.myfaces.custom.subform.submittedId";
+
+
+ public void encodeBegin(FacesContext context, UIComponent component) throws IOException
+ {
+ super.encodeBegin(context, component);
+
+ ResponseWriter writer = context.getResponseWriter();
+
+ HtmlRendererUtils.writePrettyLineSeparator(context);
+ writer.startElement(HTML.SCRIPT_ELEM, null);
+ writer.writeAttribute(org.apache.myfaces.shared_tomahawk.renderkit.html.HTML.SCRIPT_TYPE_ATTR, org.apache.myfaces.shared_tomahawk.renderkit.html.HTML.SCRIPT_TYPE_TEXT_JAVASCRIPT, null);
+
+ FormInfo parentFormInfo = RendererUtils.findNestingForm(component,context);
+ if(parentFormInfo!=null)
+ {
+ writer.writeText(createPartialSubmitJS(component.getId(), parentFormInfo.getFormName()), null);
+ }
+
+ writer.endElement(org.apache.myfaces.shared_tomahawk.renderkit.html.HTML.SCRIPT_ELEM);
+ HtmlRendererUtils.writePrettyLineSeparator(context);
+ }
+
+
+ public void decode(FacesContext context, UIComponent component)
+ {
+ super.decode(context, component);
+
+ Map paramValuesMap = context.getExternalContext().getRequestParameterMap();
+ String reqValue = (String) paramValuesMap.get(HIDDEN_PARAM_NAME);
+ if (reqValue != null && component.getId().equals(reqValue))
+ {
+ ((SubForm) component).setSubmitted(true);
+ }
+ }
+
+
+ protected String createPartialSubmitJS(String subFormId, String parentFormClientId)
+ {
+ StringBuffer script = new StringBuffer();
+ script.append("function ");
+ script.append(subFormId).append(SUBMIT_FUNCTION_SUFFIX + "()");
+ script.append(" {\n");
+ script.append("var form = document.forms['").append(parentFormClientId).append("'];\n");
+ script.append("var el = document.createElement(\"input\");\n");
+ script.append("el.type = \"hidden\";\n");
+ script.append("el.name = \"" + HIDDEN_PARAM_NAME + "\";\n");
+ script.append("el.value = \"").append(subFormId).append("\";\n");
+ script.append("form.appendChild(el);\n");
+ script.append("form.submit();\n");
+ script.append("}\n");
+
+ return script.toString();
+ }
+
+}
Propchange: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/subform/SubFormRenderer.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/tree2/Tree.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/tree2/Tree.java?rev=673836&r1=673835&r2=673836&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/tree2/Tree.java (original)
+++ myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/tree2/Tree.java Thu Jul 3 15:03:29 2008
@@ -1,62 +1,62 @@
-/*
- * 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.tree2;
-
-import javax.faces.event.ActionEvent;
-
-/**
- * @author Martin Marinschek
- */
-public interface Tree {
- void setModel(Object model);
-
- Object getModel();
-
- void setVar(String var);
-
- String getVar();
-
- TreeNode getNode();
-
- String getNodeId();
-
- void setNodeId(String nodeId);
-
- String[] getPathInformation(String nodeId);
-
- boolean isLastChild(String nodeId);
-
- TreeModel getDataModel();
-
- void expandAll();
-
- void collapseAll();
-
- void expandPath(String[] nodePath);
-
- void collapsePath(String[] nodePath);
-
- void toggleExpanded();
-
- boolean isNodeExpanded();
-
- void setNodeSelected(ActionEvent event);
-
- boolean isNodeSelected();
-}
+/*
+ * 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.tree2;
+
+import javax.faces.event.ActionEvent;
+
+/**
+ * @author Martin Marinschek
+ */
+public interface Tree {
+ void setModel(Object model);
+
+ Object getModel();
+
+ void setVar(String var);
+
+ String getVar();
+
+ TreeNode getNode();
+
+ String getNodeId();
+
+ void setNodeId(String nodeId);
+
+ String[] getPathInformation(String nodeId);
+
+ boolean isLastChild(String nodeId);
+
+ TreeModel getDataModel();
+
+ void expandAll();
+
+ void collapseAll();
+
+ void expandPath(String[] nodePath);
+
+ void collapsePath(String[] nodePath);
+
+ void toggleExpanded();
+
+ boolean isNodeExpanded();
+
+ void setNodeSelected(ActionEvent event);
+
+ boolean isNodeSelected();
+}
Propchange: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/tree2/Tree.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/dateformat/DateFormatSymbols.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/dateformat/ParserContext.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/dateformat/SimpleDateFormatter.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/dateformat/WeekDate.java
------------------------------------------------------------------------------
svn:eol-style = native