Author: abelevich
Date: 2008-04-11 05:46:06 -0400 (Fri, 11 Apr 2008)
New Revision: 7754
Modified:
trunk/ui/combobox/src/main/java/org/richfaces/renderkit/ComboBoxBaseRenderer.java
trunk/ui/combobox/src/main/resources/org/richfaces/renderkit/html/css/combobox.xcss
trunk/ui/combobox/src/main/templates/combobox.jspx
Log:
applying review
Modified:
trunk/ui/combobox/src/main/java/org/richfaces/renderkit/ComboBoxBaseRenderer.java
===================================================================
---
trunk/ui/combobox/src/main/java/org/richfaces/renderkit/ComboBoxBaseRenderer.java 2008-04-11
09:45:39 UTC (rev 7753)
+++
trunk/ui/combobox/src/main/java/org/richfaces/renderkit/ComboBoxBaseRenderer.java 2008-04-11
09:46:06 UTC (rev 7754)
@@ -3,7 +3,6 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -14,10 +13,9 @@
import javax.faces.model.SelectItem;
import org.ajax4jsf.javascript.JSFunctionDefinition;
-import org.ajax4jsf.javascript.JSReference;
-import org.ajax4jsf.javascript.ScriptString;
import org.ajax4jsf.javascript.ScriptUtils;
import org.ajax4jsf.renderkit.HeaderResourcesRendererBase;
+import org.ajax4jsf.renderkit.RendererUtils;
import org.ajax4jsf.renderkit.RendererUtils.HTML;
import org.ajax4jsf.util.InputUtils;
import org.ajax4jsf.util.SelectUtils;
@@ -47,10 +45,15 @@
comboBox = (UIComboBox) component;
} else {
if (logger.isDebugEnabled()) {
- logger.debug("No decoding necessary since the component " +
component.getId() + " is not an instance or a sub class of UIComboBox");
+ logger.debug("No decoding necessary since the component " + component.getId()
+ " is not an instance or a sub class of UIComboBox");
}
return;
}
+
+ String clientId = comboBox.getClientId(context);
+ if (clientId == null) {
+ throw new NullPointerException("component client id is NULL");
+ }
if (InputUtils.isDisabled(comboBox) || InputUtils.isReadOnly(comboBox)) {
if (logger.isDebugEnabled()) {
@@ -58,60 +61,55 @@
}
}
- String clientId = component.getClientId(context);
- if (clientId == null) {
- throw new NullPointerException("component " +
comboBox.getClientId(context) + " client id is NULL");
- }
-
- clientId = clientId + "comboboxValue";
- Map request = context.getExternalContext().getRequestParameterMap();
- if (request.containsKey(clientId)) {
- String newValue = (String) request.get(clientId);
+ Map <String, String> request =
context.getExternalContext().getRequestParameterMap();
+ String newValue = (String) request.get(clientId);
+ if (newValue != null) {
comboBox.setSubmittedValue(newValue);
}
}
- public List encodeItems(FacesContext context, UIComponent component) throws
IOException {
- if (!isAcceptableComponent(component)) {
- return null;
- }
-
- UIComboBox comboBox = (UIComboBox) component;
- Object suggestionValues = comboBox.getSuggestionValues();
- ResponseWriter writer = context.getResponseWriter();
+ public List<Object> encodeItems(FacesContext context, UIComponent component)
throws IOException, IllegalArgumentException {
+ if (!isAcceptableComponent(component)) {
+ return null;
+ }
- List values = new ArrayList();
-
- if (suggestionValues != null) {
- if (suggestionValues instanceof Collection) {
- for (Iterator iterator = ((Collection) suggestionValues).iterator();
iterator.hasNext();) {
- String value = getConvertedStringValue(context, comboBox, iterator.next());
- values.add(value);
- encodeSuggestion(writer, comboBox, value, RICH_COMBOBOX_ITEM_CLASSES);
- }
- } else if (suggestionValues.getClass().isArray()) {
- Object[] suggestions = (Object[]) suggestionValues;
- for (int i = 0; i < suggestions.length; i++) {
- String value = getConvertedStringValue(context, comboBox, suggestions[i]);
- values.add(value);
- encodeSuggestion(writer, comboBox, value, RICH_COMBOBOX_ITEM_CLASSES);
- }
- } else {
- throw new IllegalArgumentException("suggestionValues should be Collection or
array");
- }
-
+ UIComboBox comboBox = (UIComboBox) component;
+ Object suggestionValues = comboBox.getSuggestionValues();
+ ResponseWriter writer = context.getResponseWriter();
+ List <Object>values = encodeSuggestionValues(context, component, writer,
suggestionValues);
+ List<SelectItem> selectItems = SelectUtils.getSelectItems(context, component);
+ for (SelectItem selectItem : selectItems) {
+ String value = getConvertedStringValue(context, comboBox, selectItem.getValue());
+ values.add(value);
+ encodeSuggestion(writer, comboBox, value, RICH_COMBOBOX_ITEM_CLASSES);
+
+ }
+ return values;
+ }
+
+ public List<Object> encodeSuggestionValues(FacesContext context, UIComponent
component, ResponseWriter writer,
+ Object suggestionValues) throws IOException, IllegalArgumentException {
+ ArrayList<Object> values = new ArrayList<Object>();
+ if (suggestionValues != null) {
+ if (suggestionValues instanceof Collection) {
+ Collection<Object> collection = (Collection) suggestionValues;
+ for (Object suggestionValue : collection) {
+ String value = getConvertedStringValue(context, component, suggestionValue);
+ values.add(value);
+ encodeSuggestion(writer, component, value, RICH_COMBOBOX_ITEM_CLASSES);
}
-
- List<SelectItem> selectItems = SelectUtils.getSelectItems(context, component);
- if (!selectItems.isEmpty()) {
- for (Iterator<SelectItem> iterator = selectItems.iterator();
iterator.hasNext();) {
- SelectItem selectItem = iterator.next();
- String value = getConvertedStringValue(context, comboBox, selectItem.getValue());
- values.add(value);
- encodeSuggestion(writer, comboBox, value, RICH_COMBOBOX_ITEM_CLASSES);
- }
+ } else if (suggestionValues.getClass().isArray()) {
+ Object[] suggestions = (Object[]) suggestionValues;
+ for (int i = 0; i < suggestions.length; i++) {
+ String value = getConvertedStringValue(context, component, suggestions[i]);
+ values.add(value);
+ encodeSuggestion(writer, component, value, RICH_COMBOBOX_ITEM_CLASSES);
}
- return values;
+ } else {
+ throw new IllegalArgumentException("suggestionValues should be Collection or
array");
+ }
+ }
+ return values;
}
@Override
@@ -124,10 +122,10 @@
}
public void encodeSuggestion(ResponseWriter writer, UIComponent component, String
value, String classes) throws IOException {
- writer.startElement(HTML.SPAN_ELEM, component);
- writer.writeAttribute(HTML.class_ATTRIBUTE, classes, null);
- writer.writeText(value, null);
- writer.endElement(HTML.SPAN_ELEM);
+ writer.startElement(HTML.SPAN_ELEM, component);
+ writer.writeAttribute(HTML.class_ATTRIBUTE, classes, null);
+ writer.writeText(value, null);
+ writer.endElement(HTML.SPAN_ELEM);
}
protected boolean isAcceptableComponent(UIComponent component) {
@@ -139,19 +137,7 @@
}
public String getAsEventHandler(FacesContext context, UIComponent component, String
attributeName) {
- String event = (String) component.getAttributes().get(attributeName);
- ScriptString result = JSReference.NULL;
-
- if (event != null) {
- event = event.trim();
- if (event.length() != 0) {
- JSFunctionDefinition function = new JSFunctionDefinition();
- function.addParameter("event");
- function.addToBody(event);
- result = function;
- }
- }
-
- return ScriptUtils.toScript(result);
+ JSFunctionDefinition script = RendererUtils.getAsEventHandler(context, component,
attributeName, null);
+ return ScriptUtils.toScript(script);
}
}
Modified:
trunk/ui/combobox/src/main/resources/org/richfaces/renderkit/html/css/combobox.xcss
===================================================================
---
trunk/ui/combobox/src/main/resources/org/richfaces/renderkit/html/css/combobox.xcss 2008-04-11
09:45:39 UTC (rev 7753)
+++
trunk/ui/combobox/src/main/resources/org/richfaces/renderkit/html/css/combobox.xcss 2008-04-11
09:46:06 UTC (rev 7754)
@@ -221,52 +221,19 @@
</f:verbatim>
- <u:selector name=".rich-combobox-shadow-tl">
+ <u:selector name=".rich-combobox-shadow-tl, .rich-combobox-shadow-tr,
.rich-combobox-shadow-bl, .rich-combobox-shadow-br">
<u:style name="background-image">
<f:resource
f:key="/org/richfaces/renderkit/html/images/bg_shadow.png"/>
</u:style>
</u:selector>
- <u:selector name=".rich-combobox-shadow-tr">
+ <u:selector name="input.rich-combobox-button-background,
input.rich-combobox-button-background-disabled,
input.rich-combobox-button-background-inactive">
<u:style name="background-image">
- <f:resource
f:key="/org/richfaces/renderkit/html/images/bg_shadow.png"/>
- </u:style>
- </u:selector>
-
- <u:selector name=".rich-combobox-shadow-bl">
- <u:style name="background-image">
- <f:resource
f:key="/org/richfaces/renderkit/html/images/bg_shadow.png"/>
- </u:style>
- </u:selector>
-
- <u:selector name=".rich-combobox-shadow-br">
- <u:style name="background-image">
- <f:resource
f:key="/org/richfaces/renderkit/html/images/bg_shadow.png"/>
- </u:style>
- </u:selector>
-
-
- <u:selector name="input.rich-combobox-button-background">
- <u:style name="background-image">
<f:resource
f:key="org.richfaces.renderkit.html.images.SpinnerButtonGradient" />
</u:style>
<u:style name="background-color" skin="tabBackgroundColor"/>
</u:selector>
- <u:selector name="input.rich-combobox-button-background-disabled">
- <u:style name="background-image">
- <f:resource
f:key="org.richfaces.renderkit.html.images.SpinnerButtonGradient" />
- </u:style>
- <u:style name="background-color" skin="tabBackgroundColor"/>
- </u:selector>
-
- <u:selector name="input.rich-combobox-button-background-inactive">
- <u:style name="background-image">
- <f:resource
f:key="org.richfaces.renderkit.html.images.SpinnerButtonGradient" />
- </u:style>
- <u:style name="background-color" skin="tabBackgroundColor"/>
- </u:selector>
-
<u:selector name="input.rich-combobox-button-pressed-background">
<u:style name="background-image">
<f:resource
f:key="org.richfaces.renderkit.html.images.ComboBoxButtonPressGradient" />
@@ -274,7 +241,7 @@
<u:style name="background-color" skin="tabBackgroundColor"/>
</u:selector>
- <u:selector name="input.rich-combobox-button-icon">
+ <u:selector name="input.rich-combobox-button-icon,
input.rich-combobox-button-icon-inactive">
<u:style name="background-image">
<f:resource
f:key="org.richfaces.renderkit.html.images.ComboBoxArrowImage" />
</u:style>
@@ -286,85 +253,35 @@
</u:style>
</u:selector>
- <u:selector name="input.rich-combobox-button-icon-inactive">
- <u:style name="background-image">
- <f:resource
f:key="org.richfaces.renderkit.html.images.ComboBoxArrowImage" />
- </u:style>
- </u:selector>
-
- <u:selector name="input.rich-combobox-button">
+ <u:selector name="input.rich-combobox-button,
input.rich-combobox-button-inactive, input.rich-combobox-button-disabled">
<u:style name="border-top-color" skin="panelBorderColor"/>
<u:style name="border-left-color" skin="panelBorderColor"/>
</u:selector>
- <u:selector name="input.rich-combobox-button-inactive">
- <u:style name="border-top-color" skin="panelBorderColor"/>
- <u:style name="border-left-color" skin="panelBorderColor"/>
- </u:selector>
-
- <u:selector name="input.rich-combobox-button-disabled">
- <u:style name="border-top-color" skin="panelBorderColor"/>
- <u:style name="border-left-color" skin="panelBorderColor"/>
- </u:selector>
-
- <u:selector name="input.rich-combobox-font">
+ <u:selector name=".rich-combobox-font, input.rich-combobox-font">
<u:style name="font-size" skin="generalSizeFont"/>
<u:style name="font-family" skin="generalFamilyFont"/>
<u:style name="color" skin="generalTextColor"/>
</u:selector>
- <u:selector name=".rich-combobox-font">
- <u:style name="font-size" skin="generalSizeFont"/>
- <u:style name="font-family" skin="generalFamilyFont"/>
- <u:style name="color" skin="generalTextColor"/>
- </u:selector>
-
- <u:selector name="input.rich-combobox-font-disabled">
+ <u:selector name="input.rich-combobox-font-disabled,
.rich-combobox-font-disabled">
<u:style name="font-family" skin="headerFamilyFont"/>
<u:style name="font-size" skin="headerSizeFont"/>
</u:selector>
- <u:selector name=".rich-combobox-font-disabled">
- <u:style name="font-family" skin="headerFamilyFont"/>
- <u:style name="font-size" skin="headerSizeFont"/>
- </u:selector>
-
- <u:selector name="input.rich-combobox-font-inactive">
+ <u:selector name="input.rich-combobox-font-inactive,
.rich-combobox-font-inactive, .rich-combobox-item">
<u:style name="font-size" skin="generalSizeFont"/>
<u:style name="font-family" skin="generalFamilyFont"/>
<u:style name="color" skin="generalTextColor"/>
</u:selector>
- <u:selector name=".rich-combobox-font-inactive">
- <u:style name="font-size" skin="generalSizeFont"/>
- <u:style name="font-family" skin="generalFamilyFont"/>
- <u:style name="color" skin="generalTextColor"/>
- </u:selector>
-
-
- <u:selector name=".rich-combobox-input">
+
+ <u:selector name=".rich-combobox-input, .rich-combobox-input-disabled,
.rich-combobox-input-inactive">
<u:style name="background-color"
skin="controlBackgroundColor"/>
<u:style name="border-bottom-color"
skin="panelBorderColor"/>
<u:style name="border-right-color" skin="panelBorderColor"/>
</u:selector>
-
- <u:selector name=".rich-combobox-input-disabled">
- <u:style name="background-color"
skin="controlBackgroundColor"/>
- <u:style name="border-bottom-color"
skin="panelBorderColor"/>
- <u:style name="border-right-color" skin="panelBorderColor"/>
- </u:selector>
-
- <u:selector name=".rich-combobox-input-inactive">
- <u:style name="background-color"
skin="controlBackgroundColor"/>
- <u:style name="border-bottom-color" skin="panelBorderColor"/>
- <u:style name="border-right-color" skin="panelBorderColor"/>
- </u:selector>
- <u:selector name=".rich-combobox-item">
- <u:style name="font-size" skin="generalSizeFont"/>
- <u:style name="font-family" skin="generalFamilyFont"/>
- <u:style name="color" skin="generalTextColor"/>
- </u:selector>
<u:selector name=".rich-combobox-item-selected">
<u:style name="background-color" skin="headerBackgroundColor"
/>
Modified: trunk/ui/combobox/src/main/templates/combobox.jspx
===================================================================
--- trunk/ui/combobox/src/main/templates/combobox.jspx 2008-04-11 09:45:39 UTC (rev 7753)
+++ trunk/ui/combobox/src/main/templates/combobox.jspx 2008-04-11 09:46:06 UTC (rev 7754)
@@ -87,7 +87,7 @@
String valueStyle = "rich-combobox-font-inactive";
value = getConvertedStringValue(context, component,value);
- if (value == null || value.equals("")) {
+ if ("".equals(value)) {
valueStyle = "rich-combobox-font-disabled";
value = defaultLabel;
}
@@ -98,7 +98,7 @@
variables.setVariable("inputStyle", inputStyle);
Object inputClass = component.getAttributes().get("inputClass");
- if(inputClass!=null && inputClass.equals("")) {
+ if("".equals(inputClass)) {
inputClass = null;
}
variables.setVariable("inputClass", inputClass);
@@ -107,7 +107,7 @@
variables.setVariable("inputDisabledStyle", inputDisabledStyle);
Object inputDisabledClass =
component.getAttributes().get("inputDisabledClass");
- if(inputDisabledClass!=null && inputDisabledClass.equals("")) {
+ if("".equals(inputDisabledClass)) {
inputDisabledClass = null;
}
variables.setVariable("inputDisabledClass", inputDisabledClass);
@@ -116,14 +116,14 @@
variables.setVariable("inputInactiveStyle", inputInactiveStyle);
Object inputInactiveClass =
component.getAttributes().get("inputInactiveClass");
- if(inputInactiveClass!=null && inputInactiveClass.equals("")) {
+ if("".equals(inputInactiveClass)) {
inputInactiveClass = null;
}
variables.setVariable("inputInactiveClass", inputInactiveClass);
Object buttonInactiveClass =
component.getAttributes().get("buttonInactiveClass");
- if(buttonInactiveClass!=null && buttonInactiveClass.equals(""))
{
+ if("".equals(buttonInactiveClass)) {
buttonInactiveClass = null;
}
variables.setVariable("buttonInactiveClass", buttonInactiveClass);
@@ -132,7 +132,7 @@
variables.setVariable("buttonInactiveStyle", buttonInactiveStyle);
Object buttonDisabledClass =
component.getAttributes().get("buttonDisabledClass");
- if(buttonDisabledClass!=null && buttonDisabledClass.equals(""))
{
+ if("".equals(buttonDisabledClass)) {
buttonDisabledClass = null;
}
variables.setVariable("buttonDisabledClass", buttonDisabledClass);
@@ -141,7 +141,7 @@
variables.setVariable("buttonDisabledStyle", buttonDisabledStyle);
Object buttonClass = component.getAttributes().get("buttonClass");
- if(buttonClass!=null && buttonClass.equals("")) {
+ if("".equals(buttonClass)) {
buttonClass = null;
}
variables.setVariable("buttonClass", buttonClass);
@@ -153,7 +153,7 @@
variables.setVariable("listStyle", listStyle);
Object listClass = component.getAttributes().get("listClass");
- if(listClass!=null && listClass.equals("")) {
+ if("".equals(listClass)) {
listClass = null;
}
variables.setVariable("listClass", listClass);
@@ -165,31 +165,31 @@
variables.setVariable("style", style);
Object itemClass = component.getAttributes().get("itemClass");
- if(itemClass!=null && itemClass.equals("")) {
+ if("".equals(itemClass)) {
itemClass = null;
}
variables.setVariable("itemClass", itemClass);
Object itemSelectedClass =
component.getAttributes().get("itemSelectedClass");
- if(itemSelectedClass!=null && itemSelectedClass.equals("")) {
+ if("".equals(itemSelectedClass)) {
itemSelectedClass = null;
}
variables.setVariable("itemSelectedClass", itemSelectedClass);
String buttonIcon = (String)component.getAttributes().get("buttonIcon");
- if (buttonIcon != null && !buttonIcon.equals("")) {
+ if (!"".equals(buttonIcon)) {
buttonIcon = "url('" + buttonIcon + "')";
}
variables.setVariable("buttonIcon", buttonIcon);
String buttonIconDisabled =
(String)component.getAttributes().get("buttonIconDisabled");
- if (buttonIconDisabled != null && !buttonIconDisabled.equals(""))
{
+ if (!"".equals(buttonIconDisabled)) {
buttonIconDisabled = "url('" + buttonIconDisabled +
"')";
}
variables.setVariable("buttonIconDisabled", buttonIconDisabled);
String buttonIconInactive =
(String)component.getAttributes().get("buttonIconInactive");
- if (buttonIconInactive != null && !buttonIconInactive.equals(""))
{
+ if (!"".equals(buttonIconInactive)) {
buttonIconInactive = "url('" + buttonIconInactive +
"')";
}
variables.setVariable("buttonIconInactive", buttonIconInactive);
@@ -202,7 +202,7 @@
<div id="#{clientId}">
<div id="#{clientId}combobox" class="rich-combobox-font rich-combobox
#{styleClass}" style="width:#{listWidth};#{style}"
x:passThruWithExclusions="value,name,type,id,styleClass,class,style,size,autocomplete,disabled,onchange">
- <input id="#{clientId}comboboxValue"
name="#{clientId}comboboxValue" type="hidden"/>
+ <input id="#{clientId}comboboxValue" name="#{clientId}"
type="hidden"/>
<div class="rich-combobox-list-cord"></div>
<div class="rich-combobox-font rich-combobox-shell"
style="width:#{width};z-index:1;">
<input id="#{clientId}comboboxField"