You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lo...@apache.org on 2014/02/24 10:14:10 UTC
svn commit: r1571193 - in /myfaces/tobago/trunk:
tobago-core/src/main/java/org/apache/myfaces/tobago/util/
tobago-example/tobago-example-test/src/main/java/org/apache/myfaces/tobago/example/test/
tobago-example/tobago-example-test/src/main/webapp/test/...
Author: lofwyr
Date: Mon Feb 24 09:14:10 2014
New Revision: 1571193
URL: http://svn.apache.org/r1571193
Log:
TOBAGO-1362: Support dynamic list of objects for f:selectItems
Added:
myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/webapp/test/selectItem/list-of-objects.xhtml
myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/util/SelectItemUtils.java
Modified:
myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/util/ComponentUtils.java
myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/java/org/apache/myfaces/tobago/example/test/SelectItemModel.java
myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/MenuCommandRenderer.java
myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/SelectManyListboxRenderer.java
myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/SelectManyShuttleRenderer.java
myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/SelectOneChoiceRenderer.java
myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/SelectOneListboxRenderer.java
myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/SelectOneRadioRenderer.java
myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/ToolBarRendererBase.java
myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/util/HtmlRendererUtils.java
myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/util/RenderUtils.java
Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/util/ComponentUtils.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/util/ComponentUtils.java?rev=1571193&r1=1571192&r2=1571193&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/util/ComponentUtils.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/util/ComponentUtils.java Mon Feb 24 09:14:10 2014
@@ -669,7 +669,10 @@ public final class ComponentUtils {
valueBinding.setValue(context, value);
}
-
+ /**
+ * @deprecated Since Tobago 2.0
+ */
+ @Deprecated
public static boolean hasSelectedValue(final List<SelectItem> items, final Object value) {
for (final SelectItem item : items) {
if (item.getValue().equals(value)) {
Modified: myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/java/org/apache/myfaces/tobago/example/test/SelectItemModel.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/java/org/apache/myfaces/tobago/example/test/SelectItemModel.java?rev=1571193&r1=1571192&r2=1571193&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/java/org/apache/myfaces/tobago/example/test/SelectItemModel.java (original)
+++ myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/java/org/apache/myfaces/tobago/example/test/SelectItemModel.java Mon Feb 24 09:14:10 2014
@@ -32,21 +32,31 @@ public class SelectItemModel {
private boolean switch1;
private boolean switch2 = true;
- private SelectItem[] availableCurrencies;
+ private final SelectItem[] availableCurrencies;
+
+ private final Currency[] availableCurrenciesAsObject;
public SelectItemModel() {
- availableCurrencies = new SelectItem[]{
- new SelectItem(Currency.getInstance("JPY")),
- new SelectItem(Currency.getInstance("TTD")),
- new SelectItem(Currency.getInstance("USD")),
- new SelectItem(Currency.getInstance("EUR")),
+ availableCurrenciesAsObject = new Currency[]{
+ Currency.getInstance("JPY"),
+ Currency.getInstance("TTD"),
+ Currency.getInstance("USD"),
+ Currency.getInstance("EUR")
};
+ availableCurrencies = new SelectItem[availableCurrenciesAsObject.length];
+ for (int i = 0; i < availableCurrenciesAsObject.length; i++) {
+ availableCurrencies[i] = new SelectItem(availableCurrenciesAsObject[i]);
+ }
}
public SelectItem[] getAvailableCurrencies() {
return availableCurrencies;
}
+ public Currency[] getAvailableCurrenciesAsObject() {
+ return availableCurrenciesAsObject;
+ }
+
public int getNumber() {
return number;
}
Added: myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/webapp/test/selectItem/list-of-objects.xhtml
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/webapp/test/selectItem/list-of-objects.xhtml?rev=1571193&view=auto
==============================================================================
--- myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/webapp/test/selectItem/list-of-objects.xhtml (added)
+++ myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/webapp/test/selectItem/list-of-objects.xhtml Mon Feb 24 09:14:10 2014
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * 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.
+-->
+
+<f:view
+ xmlns:tc="http://myfaces.apache.org/tobago/component"
+ xmlns:tx="http://myfaces.apache.org/tobago/extension"
+ xmlns:ui="http://java.sun.com/jsf/facelets"
+ xmlns:f="http://java.sun.com/jsf/core">
+
+ <tc:page>
+ <tc:gridLayoutConstraint width="600px" height="600px"/>
+ <f:facet name="layout">
+ <tc:gridLayout rows="auto;*" />
+ </f:facet>
+
+ <tc:messages/>
+
+ <tc:selectOneRadio required="true">
+ <f:selectItems value="#{selectItemModel.availableCurrenciesAsObject}" var="currency"
+ itemValue="#{currency.currencyCode}" itemLabel="#{currency.displayName}" />
+ </tc:selectOneRadio>
+
+ <tc:button label="Submit"/>
+
+ </tc:page>
+</f:view>
Modified: myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/MenuCommandRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/MenuCommandRenderer.java?rev=1571193&r1=1571192&r2=1571193&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/MenuCommandRenderer.java (original)
+++ myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/MenuCommandRenderer.java Mon Feb 24 09:14:10 2014
@@ -41,6 +41,7 @@ import org.apache.myfaces.tobago.renderk
import org.apache.myfaces.tobago.renderkit.html.JsonUtils;
import org.apache.myfaces.tobago.renderkit.html.util.HtmlRendererUtils;
import org.apache.myfaces.tobago.renderkit.util.RenderUtils;
+import org.apache.myfaces.tobago.renderkit.util.SelectItemUtils;
import org.apache.myfaces.tobago.util.ComponentUtils;
import org.apache.myfaces.tobago.webapp.TobagoResponseWriter;
import org.slf4j.Logger;
@@ -51,7 +52,6 @@ import javax.faces.component.UISelectOne
import javax.faces.context.FacesContext;
import javax.faces.model.SelectItem;
import java.io.IOException;
-import java.util.List;
/**
* Does the decoding with parent class CommandRendererBase.
@@ -84,9 +84,8 @@ public class MenuCommandRenderer extends
// radio menu
final String clientId = menu.getClientId(facesContext);
final UISelectOne radio = (UISelectOne) menu.getFacet(Facets.RADIO);
- final List<SelectItem> items = RenderUtils.getSelectItems(radio);
final String hiddenId = radio.getClientId(facesContext);
- for (final SelectItem item : items) {
+ for (final SelectItem item : SelectItemUtils.iterator(facesContext, radio)) {
final boolean checked = item.getValue().equals(radio.getValue());
final String image = checked ? "image/MenuRadioChecked.gif" : null;
final String labelText = item.getLabel();
Modified: myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/SelectManyListboxRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/SelectManyListboxRenderer.java?rev=1571193&r1=1571192&r2=1571193&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/SelectManyListboxRenderer.java (original)
+++ myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/SelectManyListboxRenderer.java Mon Feb 24 09:14:10 2014
@@ -26,7 +26,7 @@ import org.apache.myfaces.tobago.renderk
import org.apache.myfaces.tobago.renderkit.html.HtmlAttributes;
import org.apache.myfaces.tobago.renderkit.html.HtmlElements;
import org.apache.myfaces.tobago.renderkit.html.util.HtmlRendererUtils;
-import org.apache.myfaces.tobago.renderkit.util.RenderUtils;
+import org.apache.myfaces.tobago.renderkit.util.SelectItemUtils;
import org.apache.myfaces.tobago.util.ComponentUtils;
import org.apache.myfaces.tobago.webapp.TobagoResponseWriter;
import org.slf4j.Logger;
@@ -36,7 +36,6 @@ import javax.faces.component.UIComponent
import javax.faces.context.FacesContext;
import javax.faces.model.SelectItem;
import java.io.IOException;
-import java.util.List;
public class SelectManyListboxRenderer extends SelectManyRendererBase {
@@ -57,9 +56,9 @@ public class SelectManyListboxRenderer e
final TobagoResponseWriter writer = HtmlRendererUtils.getTobagoResponseWriter(facesContext);
final String id = select.getClientId(facesContext);
- final List<SelectItem> items = RenderUtils.getSelectItems(select);
+ final Iterable<SelectItem> items = SelectItemUtils.iterator(facesContext, select);
final boolean readonly = select.isReadonly();
- final boolean disabled = items.size() == 0 || select.isDisabled() || readonly;
+ final boolean disabled = !items.iterator().hasNext() || select.isDisabled() || readonly;
final String title = HtmlRendererUtils.getTitleFromTipAndMessages(facesContext, select);
writer.startElement(HtmlElements.SELECT, select);
Modified: myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/SelectManyShuttleRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/SelectManyShuttleRenderer.java?rev=1571193&r1=1571192&r2=1571193&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/SelectManyShuttleRenderer.java (original)
+++ myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/SelectManyShuttleRenderer.java Mon Feb 24 09:14:10 2014
@@ -29,7 +29,7 @@ import org.apache.myfaces.tobago.renderk
import org.apache.myfaces.tobago.renderkit.html.HtmlButtonTypes;
import org.apache.myfaces.tobago.renderkit.html.HtmlElements;
import org.apache.myfaces.tobago.renderkit.html.util.HtmlRendererUtils;
-import org.apache.myfaces.tobago.renderkit.util.RenderUtils;
+import org.apache.myfaces.tobago.renderkit.util.SelectItemUtils;
import org.apache.myfaces.tobago.util.ComponentUtils;
import org.apache.myfaces.tobago.webapp.TobagoResponseWriter;
@@ -37,7 +37,6 @@ import javax.faces.component.UIComponent
import javax.faces.context.FacesContext;
import javax.faces.model.SelectItem;
import java.io.IOException;
-import java.util.List;
public class SelectManyShuttleRenderer extends SelectManyRendererBase {
@@ -73,8 +72,8 @@ public class SelectManyShuttleRenderer e
style.setHeight(style.getHeight().subtract(labelHeight));
style.setTop(style.getTop().add(labelHeight));
}
- final List<SelectItem> items = RenderUtils.getSelectItems(select);
- final boolean disabled = items.size() == 0 || select.isDisabled() || select.isReadonly();
+ final Iterable<SelectItem> items = SelectItemUtils.iterator(facesContext, select);
+ final boolean disabled = !items.iterator().hasNext() || select.isDisabled() || select.isReadonly();
final String unselectedLabel = select.getUnselectedLabel();
if (unselectedLabel != null) {
Modified: myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/SelectOneChoiceRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/SelectOneChoiceRenderer.java?rev=1571193&r1=1571192&r2=1571193&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/SelectOneChoiceRenderer.java (original)
+++ myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/SelectOneChoiceRenderer.java Mon Feb 24 09:14:10 2014
@@ -27,7 +27,7 @@ import org.apache.myfaces.tobago.renderk
import org.apache.myfaces.tobago.renderkit.html.HtmlAttributes;
import org.apache.myfaces.tobago.renderkit.html.HtmlElements;
import org.apache.myfaces.tobago.renderkit.html.util.HtmlRendererUtils;
-import org.apache.myfaces.tobago.renderkit.util.RenderUtils;
+import org.apache.myfaces.tobago.renderkit.util.SelectItemUtils;
import org.apache.myfaces.tobago.util.ComponentUtils;
import org.apache.myfaces.tobago.webapp.TobagoResponseWriter;
import org.slf4j.Logger;
@@ -37,7 +37,6 @@ import javax.faces.component.UIComponent
import javax.faces.context.FacesContext;
import javax.faces.model.SelectItem;
import java.io.IOException;
-import java.util.List;
public class SelectOneChoiceRenderer extends SelectOneRendererBase {
@@ -58,9 +57,9 @@ public class SelectOneChoiceRenderer ext
final TobagoResponseWriter writer = HtmlRendererUtils.getTobagoResponseWriter(facesContext);
final String id = select.getClientId(facesContext);
- final List<SelectItem> items = RenderUtils.getSelectItems(select);
+ final Iterable<SelectItem> items = SelectItemUtils.iterator(facesContext, select);
final String title = HtmlRendererUtils.getTitleFromTipAndMessages(facesContext, select);
- final boolean disabled = items.size() == 0 || select.isDisabled() || select.isReadonly();
+ final boolean disabled = !items.iterator().hasNext() || select.isDisabled() || select.isReadonly();
writer.startElement(HtmlElements.SELECT, select);
writer.writeNameAttribute(id);
Modified: myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/SelectOneListboxRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/SelectOneListboxRenderer.java?rev=1571193&r1=1571192&r2=1571193&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/SelectOneListboxRenderer.java (original)
+++ myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/SelectOneListboxRenderer.java Mon Feb 24 09:14:10 2014
@@ -26,7 +26,7 @@ import org.apache.myfaces.tobago.renderk
import org.apache.myfaces.tobago.renderkit.html.HtmlAttributes;
import org.apache.myfaces.tobago.renderkit.html.HtmlElements;
import org.apache.myfaces.tobago.renderkit.html.util.HtmlRendererUtils;
-import org.apache.myfaces.tobago.renderkit.util.RenderUtils;
+import org.apache.myfaces.tobago.renderkit.util.SelectItemUtils;
import org.apache.myfaces.tobago.util.ComponentUtils;
import org.apache.myfaces.tobago.webapp.TobagoResponseWriter;
import org.slf4j.Logger;
@@ -36,7 +36,6 @@ import javax.faces.component.UIComponent
import javax.faces.context.FacesContext;
import javax.faces.model.SelectItem;
import java.io.IOException;
-import java.util.List;
public class SelectOneListboxRenderer extends SelectOneRendererBase {
@@ -57,8 +56,8 @@ public class SelectOneListboxRenderer ex
final TobagoResponseWriter writer = HtmlRendererUtils.getTobagoResponseWriter(facesContext);
final String id = select.getClientId(facesContext);
- final List<SelectItem> items = RenderUtils.getSelectItems(select);
- final boolean disabled = items.size() == 0 || select.isDisabled() || select.isReadonly();
+ final Iterable<SelectItem> items = SelectItemUtils.iterator(facesContext, select);
+ final boolean disabled = !items.iterator().hasNext() || select.isDisabled() || select.isReadonly();
writer.startElement(HtmlElements.SELECT, select);
writer.writeNameAttribute(id);
Modified: myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/SelectOneRadioRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/SelectOneRadioRenderer.java?rev=1571193&r1=1571192&r2=1571193&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/SelectOneRadioRenderer.java (original)
+++ myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/SelectOneRadioRenderer.java Mon Feb 24 09:14:10 2014
@@ -31,6 +31,7 @@ import org.apache.myfaces.tobago.renderk
import org.apache.myfaces.tobago.renderkit.html.HtmlInputTypes;
import org.apache.myfaces.tobago.renderkit.html.util.HtmlRendererUtils;
import org.apache.myfaces.tobago.renderkit.util.RenderUtils;
+import org.apache.myfaces.tobago.renderkit.util.SelectItemUtils;
import org.apache.myfaces.tobago.util.ComponentUtils;
import org.apache.myfaces.tobago.webapp.TobagoResponseWriter;
@@ -39,7 +40,6 @@ import javax.faces.component.UISelectOne
import javax.faces.context.FacesContext;
import javax.faces.model.SelectItem;
import java.io.IOException;
-import java.util.List;
public class SelectOneRadioRenderer extends SelectOneRendererBase {
@@ -56,7 +56,7 @@ public class SelectOneRadioRenderer exte
final TobagoResponseWriter writer = HtmlRendererUtils.getTobagoResponseWriter(facesContext);
final String id = select.getClientId(facesContext);
- final List<SelectItem> items = RenderUtils.getItemsToRender(select);
+ final Iterable<SelectItem> items = SelectItemUtils.iterator(facesContext, select);
final String title = HtmlRendererUtils.getTitleFromTipAndMessages(facesContext, select);
final boolean disabled = select.isDisabled();
final boolean readonly = select.isReadonly();
@@ -121,8 +121,12 @@ public class SelectOneRadioRenderer exte
if (select.isInline()) {
return heightOfOne;
} else {
- final List<SelectItem> items = RenderUtils.getItemsToRender((UISelectOne) component);
- return heightOfOne.multiply(items.size());
+ final Iterable<SelectItem> items = SelectItemUtils.iterator(facesContext, (UISelectOne) component);
+ int count = 0;
+ for(SelectItem ignored : items) {
+ count++;
+ }
+ return heightOfOne.multiply(count);
}
}
}
Modified: myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/ToolBarRendererBase.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/ToolBarRendererBase.java?rev=1571193&r1=1571192&r2=1571193&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/ToolBarRendererBase.java (original)
+++ myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/ToolBarRendererBase.java Mon Feb 24 09:14:10 2014
@@ -48,6 +48,7 @@ import org.apache.myfaces.tobago.renderk
import org.apache.myfaces.tobago.renderkit.html.JsonUtils;
import org.apache.myfaces.tobago.renderkit.html.util.HtmlRendererUtils;
import org.apache.myfaces.tobago.renderkit.util.RenderUtils;
+import org.apache.myfaces.tobago.renderkit.util.SelectItemUtils;
import org.apache.myfaces.tobago.util.ComponentUtils;
import org.apache.myfaces.tobago.util.CreateComponentUtils;
import org.apache.myfaces.tobago.util.FacetUtils;
@@ -59,7 +60,6 @@ import javax.faces.component.UIComponent
import javax.faces.context.FacesContext;
import javax.faces.model.SelectItem;
import java.io.IOException;
-import java.util.List;
public abstract class ToolBarRendererBase extends LayoutComponentRendererBase {
@@ -121,15 +121,15 @@ public abstract class ToolBarRendererBas
final FacesContext facesContext, final UIToolBar toolBar, final AbstractUICommandBase command,
final TobagoResponseWriter writer, Measure width) throws IOException {
- final List<SelectItem> items;
+ final Iterable<SelectItem> items;
UIMenuSelectOne radio = (UIMenuSelectOne) command.getFacet(Facets.RADIO);
if (radio == null) {
- items = RenderUtils.getSelectItems(command);
+ items = SelectItemUtils.iterator(facesContext, command);
radio = CreateComponentUtils.createUIMenuSelectOneFacet(facesContext, command);
radio.setId(facesContext.getViewRoot().createUniqueId());
} else {
- items = RenderUtils.getSelectItems(radio);
+ items = SelectItemUtils.iterator(facesContext, radio);
}
if (radio != null) {
@@ -138,7 +138,7 @@ public abstract class ToolBarRendererBas
final Object value = radio.getValue();
String currentValue = "";
- boolean markFirst = !ComponentUtils.hasSelectedValue(items, value);
+ boolean markFirst = !hasSelectedValue(items, value);
final String radioId = radio.getClientId(facesContext);
for (final SelectItem item : items) {
final String labelText = item.getLabel();
@@ -594,4 +594,14 @@ public abstract class ToolBarRendererBas
public boolean getRendersChildren() {
return true;
}
+
+ private boolean hasSelectedValue(final Iterable<SelectItem> items, final Object value) {
+ for (final SelectItem item : items) {
+ if (item.getValue().equals(value)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
}
Modified: myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/util/HtmlRendererUtils.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/util/HtmlRendererUtils.java?rev=1571193&r1=1571192&r2=1571193&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/util/HtmlRendererUtils.java (original)
+++ myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/util/HtmlRendererUtils.java Mon Feb 24 09:14:10 2014
@@ -348,14 +348,13 @@ public final class HtmlRendererUtils {
return title;
}
- public static void renderSelectItems(final UIInput component, final List<SelectItem> items, final Object[] values,
+ public static void renderSelectItems(final UIInput component, final Iterable<SelectItem> items, final Object[] values,
final TobagoResponseWriter writer, final FacesContext facesContext) throws IOException {
renderSelectItems(component, items, values, null, writer, facesContext);
-
}
public static void renderSelectItems(
- final UIInput component, final List<SelectItem> items, final Object[] values, final Boolean onlySelected,
+ final UIInput component, final Iterable<SelectItem> items, final Object[] values, final Boolean onlySelected,
final TobagoResponseWriter writer, final FacesContext facesContext) throws IOException {
if (LOG.isDebugEnabled()) {
Modified: myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/util/RenderUtils.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/util/RenderUtils.java?rev=1571193&r1=1571192&r2=1571193&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/util/RenderUtils.java (original)
+++ myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/util/RenderUtils.java Mon Feb 24 09:14:10 2014
@@ -245,8 +245,8 @@ public class RenderUtils {
final List<SelectItem> items = new ArrayList<SelectItem>(indices.length);
if (selectItems.size() != 0) {
- for (final int indice : indices) {
- items.add(selectItems.get(indice));
+ for (final int index : indices) {
+ items.add(selectItems.get(index));
}
} else {
LOG.warn("No items found! rendering dummies instead!");
@@ -287,6 +287,9 @@ public class RenderUtils {
return currentValue;
}
+ /**
+ * @deprecated Please use this method with facesContext parameter
+ */
public static List<SelectItem> getSelectItems(final UIComponent component) {
final ArrayList<SelectItem> list = new ArrayList<SelectItem>();
Added: myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/util/SelectItemUtils.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/util/SelectItemUtils.java?rev=1571193&view=auto
==============================================================================
--- myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/util/SelectItemUtils.java (added)
+++ myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/util/SelectItemUtils.java Mon Feb 24 09:14:10 2014
@@ -0,0 +1,261 @@
+package org.apache.myfaces.tobago.renderkit.util;
+
+/*
+ * 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.
+ */
+
+import org.apache.myfaces.tobago.component.Attributes;
+import org.apache.myfaces.tobago.context.Markup;
+
+import javax.el.ValueExpression;
+import javax.faces.component.UIComponent;
+import javax.faces.component.UISelectItem;
+import javax.faces.component.UISelectItems;
+import javax.faces.context.FacesContext;
+import javax.faces.model.SelectItem;
+import java.lang.reflect.Array;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.NoSuchElementException;
+
+/**
+ * Based on code from MyFaces core.
+ */
+public class SelectItemUtils {
+
+ public static Iterable<SelectItem> iterator(final FacesContext facesContext, final UIComponent selector) {
+ if (selector.getChildCount() == 0) {
+ return Collections.emptyList();
+ } else {
+ return new Iterable<SelectItem>() {
+
+ private SelectItemsIterator iterator;
+
+ public Iterator<SelectItem> iterator() {
+ if (iterator == null) {
+ iterator = new SelectItemsIterator(facesContext, selector);
+ }
+ return iterator;
+ }
+ };
+ }
+ }
+
+ public static class SelectItemsIterator implements Iterator<SelectItem> {
+
+ private final FacesContext facesContext;
+ private final Iterator<UIComponent> children;
+ private Iterator<?> nestedItems;
+ private SelectItem nextItem;
+ private UISelectItems currentUISelectItems;
+
+ private SelectItemsIterator(final FacesContext facesContext, final UIComponent selector) {
+ this.children = selector.getChildren().iterator();
+ this.facesContext = facesContext;
+ }
+
+ @SuppressWarnings("unchecked")
+ public boolean hasNext() {
+ if (nextItem != null) {
+ return true;
+ }
+ if (nestedItems != null) {
+ if (nestedItems.hasNext()) {
+ return true;
+ }
+ nestedItems = null;
+ }
+
+ UIComponent child = null;
+ while (children.hasNext()) {
+ final UIComponent c = children.next();
+ // When there is other components nested that does
+ // not extends from UISelectItem or UISelectItems
+ // the behavior for this iterator is just skip this
+ // element(s) until an element that extends from these
+ // classes are found. If there is no more elements
+ // that conform this condition, just return false.
+ if (c instanceof UISelectItem || c instanceof UISelectItems) {
+ child = c;
+ break;
+ }
+ }
+ if (child == null) {
+ return false;
+ }
+
+ if (child instanceof UISelectItem) {
+ final UISelectItem uiSelectItem = (UISelectItem) child;
+ Object item = uiSelectItem.getValue();
+ if (item == null) {
+ // no value attribute --> create the SelectItem out of the other attributes
+ final Object itemValue = uiSelectItem.getItemValue();
+ String label = uiSelectItem.getItemLabel();
+ final String description = uiSelectItem.getItemDescription();
+ final boolean disabled = uiSelectItem.isItemDisabled();
+// boolean escape = uiSelectItem.isItemEscaped();
+// boolean noSelectionOption = uiSelectItem.isNoSelectionOption();
+ if (label == null) {
+ label = itemValue.toString();
+ }
+ String image = null;
+ Markup markup = null;
+ if (uiSelectItem instanceof org.apache.myfaces.tobago.component.UISelectItem) {
+ org.apache.myfaces.tobago.component.UISelectItem tobagoSelectItem
+ = (org.apache.myfaces.tobago.component.UISelectItem) uiSelectItem;
+ image = tobagoSelectItem.getItemImage();
+ markup = tobagoSelectItem.getCurrentMarkup();
+ }
+ item = new org.apache.myfaces.tobago.model.SelectItem(itemValue, label, description, disabled, image, markup);
+ } else if (!(item instanceof SelectItem)) {
+ ValueExpression expression = uiSelectItem.getValueExpression("value");
+ throw new IllegalArgumentException("ValueExpression '"
+ + (expression == null ? null : expression.getExpressionString()) + "' of UISelectItem : "
+ + child + " does not reference an Object of type SelectItem");
+ }
+ nextItem = (SelectItem) item;
+ return true;
+ } else { // UISelectItems
+ currentUISelectItems = ((UISelectItems) child);
+ final Object value = currentUISelectItems.getValue();
+
+ if (value instanceof SelectItem) {
+ nextItem = (SelectItem) value;
+ return true;
+ } else if (value != null && value.getClass().isArray()) {
+ // value is any kind of array (primitive or non-primitive)
+ // --> we have to use class Array to get the values
+ final int length = Array.getLength(value);
+ final Collection<Object> items = new ArrayList<Object>(length);
+ for (int i = 0; i < length; i++) {
+ items.add(Array.get(value, i));
+ }
+ nestedItems = items.iterator();
+ return hasNext();
+ } else if (value instanceof Iterable) {
+ // value is Iterable --> Collection, DataModel,...
+ nestedItems = ((Iterable<?>) value).iterator();
+ return hasNext();
+ } else if (value instanceof Map) {
+ final Map<Object, Object> map = ((Map<Object, Object>) value);
+ final Collection<SelectItem> items = new ArrayList<SelectItem>(map.size());
+ for (Map.Entry<Object, Object> entry : map.entrySet()) {
+ items.add(new org.apache.myfaces.tobago.model.SelectItem(entry.getValue(), entry.getKey().toString()));
+ }
+ nestedItems = items.iterator();
+ return hasNext();
+ }
+ }
+ return false;
+ }
+
+ public SelectItem next() {
+ if (!hasNext()) {
+ throw new NoSuchElementException();
+ }
+ if (nextItem != null) {
+ final SelectItem value = nextItem;
+ nextItem = null;
+ return value;
+ }
+ if (nestedItems != null) {
+ Object item = nestedItems.next();
+
+ if (!(item instanceof SelectItem)) {
+ // check new params of SelectItems (since 2.0): itemValue, itemLabel, itemDescription,...
+ // Note that according to the spec UISelectItems does not provide Getter and Setter
+ // methods for this values, so we have to use the attribute map
+ final Map<String, Object> attributeMap = currentUISelectItems.getAttributes();
+
+ // write the current item into the request map under the key listed in var, if available
+ boolean wroteRequestMapVarValue = false;
+ Object oldRequestMapVarValue = null;
+ final String var = (String) attributeMap.get(Attributes.VAR);
+ if (var != null && !"".equals(var)) {
+ // save the current value of the key listed in var from the request map
+ oldRequestMapVarValue = facesContext.getExternalContext().getRequestMap().put(var, item);
+ wroteRequestMapVarValue = true;
+ }
+
+ // check the itemValue attribute
+ Object itemValue = attributeMap.get(Attributes.ITEM_VALUE);
+ if (itemValue == null) {
+ // the itemValue attribute was not provided
+ // --> use the current item as the itemValue
+ itemValue = item;
+ }
+
+ // Spec: When iterating over the select items, toString()
+ // must be called on the string rendered attribute values
+ Object itemLabel = attributeMap.get(Attributes.ITEM_LABEL);
+ if (itemLabel == null) {
+ itemLabel = itemValue.toString();
+ } else {
+ itemLabel = itemLabel.toString();
+ }
+ Object itemDescription = attributeMap.get(Attributes.ITEM_DESCRIPTION);
+ if (itemDescription != null) {
+ itemDescription = itemDescription.toString();
+ }
+ final Boolean itemDisabled = getBooleanAttribute(currentUISelectItems, Attributes.ITEM_DISABLED, false);
+// TBD: should this be possible?
+// Boolean itemLabelEscaped = getBooleanAttribute(currentUISelectItems, ITEM_LABEL_ESCAPED_PROP, true);
+// TBD ?
+// Object noSelectionValue = attributeMap.get(NO_SELECTION_VALUE_PROP);
+ item = new org.apache.myfaces.tobago.model.SelectItem(
+ itemValue, (String) itemLabel, (String) itemDescription, itemDisabled, null);
+
+ // remove the value with the key from var from the request map, if previously written
+ if (wroteRequestMapVarValue) {
+ // If there was a previous value stored with the key from var in the request map, restore it
+ if (oldRequestMapVarValue != null) {
+ facesContext.getExternalContext().getRequestMap().put(var, oldRequestMapVarValue);
+ } else {
+ facesContext.getExternalContext().getRequestMap().remove(var);
+ }
+ }
+ }
+ return (SelectItem) item;
+ }
+ throw new NoSuchElementException();
+ }
+
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+
+ private boolean getBooleanAttribute(
+ final UIComponent component, final String attrName, final boolean defaultValue) {
+ final Object value = component.getAttributes().get(attrName);
+ if (value == null) {
+ return defaultValue;
+ } else if (value instanceof Boolean) {
+ return (Boolean) value;
+ } else {
+ // If the value is a String, parse the boolean.
+ // This makes the following code work: <tag attribute="true" />,
+ // otherwise you would have to write <tag attribute="#{true}" />.
+ return Boolean.valueOf(value.toString());
+ }
+ }
+ }
+
+}