Author: abelevich
Date: 2008-03-11 08:23:57 -0400 (Tue, 11 Mar 2008)
New Revision: 6680
Modified:
trunk/ui/combobox/src/main/java/org/richfaces/renderkit/ComboBoxBaseRenderer.java
trunk/ui/combobox/src/main/templates/combobox.jspx
trunk/ui/combobox/src/test/java/org/richfaces/renderkit/ComboBoxRendererTest.java
Log:
http://jira.jboss.com/jira/browse/RF-2445, format code, fix junit
Modified:
trunk/ui/combobox/src/main/java/org/richfaces/renderkit/ComboBoxBaseRenderer.java
===================================================================
---
trunk/ui/combobox/src/main/java/org/richfaces/renderkit/ComboBoxBaseRenderer.java 2008-03-11
11:35:33 UTC (rev 6679)
+++
trunk/ui/combobox/src/main/java/org/richfaces/renderkit/ComboBoxBaseRenderer.java 2008-03-11
12:23:57 UTC (rev 6680)
@@ -36,197 +36,190 @@
*/
public class ComboBoxBaseRenderer extends HeaderResourcesRendererBase {
- private List valuesList = null;
-
- private final String RICH_COMBOBOX_ITEM_CLASSES = "rich-combobox-item
rich-combobox-item-normal";
- private static Log logger = LogFactory.getLog(ComboBoxBaseRenderer.class);
-
-
- protected Class<? extends UIComponent> getComponentClass() {
- return UIComboBox.class;
+ private List valuesList = null;
+ private final String RICH_COMBOBOX_ITEM_CLASSES = "rich-combobox-item
rich-combobox-item-normal";
+ private static Log logger = LogFactory.getLog(ComboBoxBaseRenderer.class);
+
+ protected Class<? extends UIComponent> getComponentClass() {
+ return UIComboBox.class;
+ }
+
+ protected void doDecode(FacesContext context, UIComponent component) {
+ UIComboBox comboBox = null;
+
+ if (component instanceof UIComboBox) {
+ 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");
+ }
+ return;
}
-
- protected void doDecode(FacesContext context, UIComponent component) {
- UIComboBox comboBox = null;
- if (component instanceof UIComboBox) {
- 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");
- }
- return;
- }
-
- if (InputUtils.isDisabled(comboBox) || InputUtils.isReadOnly(comboBox)) {
- if (logger.isDebugEnabled()) {
- logger.debug(("No decoding necessary since the component "
- + component.getId() + " is disabled"));
- }
- }
-
- String clientId = component.getClientId(context);
- if (clientId == null) {
- throw new NullPointerException("component " + comboBox.getClientId(context)
+ " client id is NULL" );
- }
-
- clientId = "comboboxValue" + clientId;
- Map request = context.getExternalContext().getRequestParameterMap();
- if (request.containsKey(clientId)) {
- String newValue = (String)request.get(clientId);
- comboBox.setSubmittedValue(newValue);
- }
+ if (InputUtils.isDisabled(comboBox) || InputUtils.isReadOnly(comboBox)) {
+ if (logger.isDebugEnabled()) {
+ logger.debug(("No decoding necessary since the component " +
component.getId() + " is disabled"));
+ }
}
-
- public void encodeItems( FacesContext context, UIComponent component) throws IOException
{
- UIComboBox comboBox = (UIComboBox)component;
- Object suggestionValues = comboBox.getSuggestionValues();
- ResponseWriter writer = context.getResponseWriter();
-
- 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");
- }
-
- }
-
- 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);
- }
- }
- setValuesList(values);
+
+ String clientId = component.getClientId(context);
+ if (clientId == null) {
+ throw new NullPointerException("component " +
comboBox.getClientId(context) + " client id is NULL");
}
-
- @Override
- public Object getConvertedValue(FacesContext context, UIComponent component, Object
submittedValue) throws ConverterException {
- UIComboBox comboBox = null;
- Converter converter = null;
-
- if(component instanceof UIComboBox) {
- comboBox = (UIComboBox)component;
- converter = comboBox.getConverter();
- }
-
- return getConvertedValue(context, component, submittedValue, converter);
+
+ clientId = clientId + "comboboxValue";
+ Map request = context.getExternalContext().getRequestParameterMap();
+ if (request.containsKey(clientId)) {
+ String newValue = (String) request.get(clientId);
+ comboBox.setSubmittedValue(newValue);
}
-
- public Object getConvertedValue(FacesContext context, UIComponent component, Object
submittedValue, Converter converter) {
- Object convertedValue = null;
- String newValue = (String)submittedValue;
+ }
- ValueExpression valueExpression = component.getValueExpression("value");
-
- if (converter == null) {
- if (valueExpression != null) {
- Class valueType = valueExpression.getType(context.getELContext());
- if(valueType == null || String.class.equals(valueType) ||
Object.class.equals(valueType)){
- if(logger.isDebugEnabled()) {
- logger.debug("No conversion necessary for value " +
- newValue + " of component " + component.getClientId(context));
- }
- } else {
- converter = context.getApplication().createConverter(valueType);
- if(converter == null){
- throw new ConverterException(Messages.getMessage(Messages.NO_CONVERTER_FOUND_ERROR,
valueType.getName()));
- }
- }
- }
+ public void encodeItems(FacesContext context, UIComponent component) throws
IOException {
+ UIComboBox comboBox = (UIComboBox) component;
+ Object suggestionValues = comboBox.getSuggestionValues();
+ ResponseWriter writer = context.getResponseWriter();
+
+ 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);
}
-
- if(converter != null){
- convertedValue = converter.getAsObject(context, component, newValue);
- } else {
- convertedValue = newValue;
+ } 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);
}
- return convertedValue;
-
-
+ } else {
+ throw new IllegalArgumentException("suggestionValues should be Collection or
array");
+ }
+
}
-
- protected String getConvertedStringValue(FacesContext context, UIComponent component,
Object value) {
- Converter converter = null;
- if (component instanceof UIComboBox) {
- UIComboBox comboBox = (UIComboBox)component;
- converter = comboBox.getConverter();
- }
- return getConvertedStringValue(context, component, value, converter);
+
+ 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);
+ }
}
-
- protected String getConvertedStringValue(FacesContext context, UIComponent component,
Object value, Converter converter) {
- if (converter == null) {
- if (value == null) {
- return "";
- } else if (value instanceof String) {
- return (String) value;
- }
-
- Class converterType = value.getClass();
- if (converterType != null ) {
- converter = context.getApplication().createConverter(converterType);
- }
-
- if (converter == null) {
- return value.toString();
- }
+ setValuesList(values);
+ }
+
+ @Override
+ public Object getConvertedValue(FacesContext context, UIComponent component, Object
submittedValue) throws ConverterException {
+ UIComboBox comboBox = null;
+ Converter converter = null;
+
+ if (component instanceof UIComboBox) {
+ comboBox = (UIComboBox) component;
+ converter = comboBox.getConverter();
+ }
+
+ return getConvertedValue(context, component, submittedValue, converter);
+ }
+
+ public Object getConvertedValue(FacesContext context, UIComponent component, Object
submittedValue, Converter converter) {
+ Object convertedValue = null;
+ String newValue = (String) submittedValue;
+
+ ValueExpression valueExpression = component.getValueExpression("value");
+
+ if (converter == null) {
+ if (valueExpression != null) {
+ Class valueType = valueExpression.getType(context.getELContext());
+ if (valueType == null || String.class.equals(valueType) ||
Object.class.equals(valueType)) {
+ if (logger.isDebugEnabled()) {
+ logger.debug("No conversion necessary for value " + newValue + " of
component " + component.getClientId(context));
+ }
+ } else {
+ converter = context.getApplication().createConverter(valueType);
+ if (converter == null) {
+ throw new ConverterException(Messages.getMessage(Messages.NO_CONVERTER_FOUND_ERROR,
valueType.getName()));
+ }
}
- return converter.getAsString(context, component, value);
+ }
}
-
- 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.write(value);
- writer.endElement(HTML.SPAN_ELEM);
+
+ if (converter != null) {
+ convertedValue = converter.getAsObject(context, component, newValue);
+ } else {
+ convertedValue = newValue;
}
-
- public String getItemsTextAsJSArray(FacesContext context, UIComponent component) {
- return ScriptUtils.toScript(valuesList);
- }
-
- 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);
+ return convertedValue;
- result = function;
- }
- }
- return ScriptUtils.toScript(result);
+ }
+
+ protected String getConvertedStringValue(FacesContext context, UIComponent component,
Object value) {
+ Converter converter = null;
+ if (component instanceof UIComboBox) {
+ UIComboBox comboBox = (UIComboBox) component;
+ converter = comboBox.getConverter();
}
+ return getConvertedStringValue(context, component, value, converter);
+ }
- public List getValuesList() {
- return valuesList;
+ protected String getConvertedStringValue(FacesContext context, UIComponent component,
Object value, Converter converter) {
+ if (converter == null) {
+ if (value == null) {
+ return "";
+ } else if (value instanceof String) {
+ return (String) value;
+ }
+
+ Class converterType = value.getClass();
+ if (converterType != null) {
+ converter = context.getApplication().createConverter(converterType);
+ }
+
+ if (converter == null) {
+ return value.toString();
+ }
}
+ return converter.getAsString(context, component, value);
+ }
- public void setValuesList(List valuesList) {
- this.valuesList = valuesList;
+ 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.write(value);
+ writer.endElement(HTML.SPAN_ELEM);
+ }
+
+ public String getItemsTextAsJSArray(FacesContext context, UIComponent component) {
+ return ScriptUtils.toScript(valuesList);
+ }
+
+ 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);
+ }
+
+ public List getValuesList() {
+ return valuesList;
+ }
+
+ public void setValuesList(List valuesList) {
+ this.valuesList = valuesList;
+ }
}
Modified: trunk/ui/combobox/src/main/templates/combobox.jspx
===================================================================
--- trunk/ui/combobox/src/main/templates/combobox.jspx 2008-03-11 11:35:33 UTC (rev 6679)
+++ trunk/ui/combobox/src/main/templates/combobox.jspx 2008-03-11 12:23:57 UTC (rev 6680)
@@ -193,13 +193,13 @@
</jsp:scriptlet>
<f:resource var="spacer" name="images/spacer.gif"/>
-<div id="control#{clientId}" class="rich-combobox-font rich-combobox
#{styleClass}" style="width:#{listWidth};#{style}"
+<div id="#{clientId}" 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="comboboxValue#{clientId}"
name="comboboxValue#{clientId}" type="hidden"/>
+ <input id="#{clientId}comboboxValue"
name="#{clientId}comboboxValue" 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="comboboxField#{clientId}"
- name="comboboxField#{clientId}"
+ <input id="#{clientId}comboboxField"
+ name="#{clientId}comboboxField"
disabled="#{disabled}"
class="#{valueStyle} rich-combobox-input-inactive
#{inputDisabledClass}" type="text"
value="#{value}"
@@ -211,19 +211,19 @@
style="width:#{correction}; #{inputStyle}"
autocomplete="off"
/>
- <input id="comboBoxButtonBG#{clientId}"
+ <input id="#{clientId}comboBoxButtonBG"
readonly="true"
type="text"
value=""
class="rich-combobox-font-inactive rich-combobox-button-background
rich-combobox-button-inactive"/>
- <input id="comboboxButton#{clientId}" readonly="true"
disabled="#{disabled}" type="text" value=""
style="#{buttonStyle}; background-image: #{buttonIconNormal};"
+ <input id="#{clientId}comboboxButton" readonly="true"
disabled="#{disabled}" type="text" value=""
style="#{buttonStyle}; background-image: #{buttonIconNormal};"
class="rich-combobox-font-inactive rich-combobox-button-icon-inactive
rich-combobox-button-inactive #{buttonDisabledClass}"/>
<div class="rich-combobox-strut rich-combobox-font"
style="width:#{correction}">Strut</div>
</div>
- <div id="listParent#{clientId}" class="rich-combobox-list-cord
#{listClass}" style="display:none; #{listStyle};z-index:
3;position:absolute;">
+ <div id="#{clientId}listParent" class="rich-combobox-list-cord
#{listClass}" style="display:none; #{listStyle};z-index:
3;position:absolute;">
<div class="rich-combobox-shadow">
- <table id="shadow#{clientId}" cellpadding="0"
cellspacing="0" border="0">
+ <table id="#{clientId}shadow" cellpadding="0"
cellspacing="0" border="0">
<tr>
<td class="rich-combobox-shadow-tl">
<img src="#{spacer}" width="10" height="1"
alt="" border="0"></img><br></br>
@@ -242,9 +242,9 @@
</tr>
</table>
</div>
- <div id="listPosition#{clientId}"
class="rich-combobox-list-position">
- <div id="listDecoration#{clientId}"
class="rich-combobox-list-decoration">
- <div id="list#{clientId}"
class="rich-combobox-list-scroll">
+ <div id="#{clientId}listPosition"
class="rich-combobox-list-position">
+ <div id="#{clientId}listDecoration"
class="rich-combobox-list-decoration">
+ <div id="#{clientId}list"
class="rich-combobox-list-scroll">
<f:call name="encodeItems"/>
</div>
</div>
@@ -293,14 +293,14 @@
}
}
- var combobox = new Richfaces.ComboBox( "control#{clientId}",
- "list#{clientId}",
- "listParent#{clientId}",
- "comboboxValue#{clientId}",
- "comboboxField#{clientId}",
- "comboboxButton#{clientId}",
- "comboBoxButtonBG#{clientId}",
- "shadow#{clientId}",
+ var combobox = new Richfaces.ComboBox( "#{clientId}",
+ "#{clientId}list",
+ "#{clientId}listParent",
+ "#{clientId}comboboxValue",
+ "#{clientId}comboboxField",
+ "#{clientId}comboboxButton",
+ "#{clientId}comboBoxButtonBG",
+ "#{clientId}shadow",
Richfaces.ComboBox.CLASSES,
"#{listWidth}", "#{listHeight}",
#{this:getItemsTextAsJSArray(context, component)},
Modified:
trunk/ui/combobox/src/test/java/org/richfaces/renderkit/ComboBoxRendererTest.java
===================================================================
---
trunk/ui/combobox/src/test/java/org/richfaces/renderkit/ComboBoxRendererTest.java 2008-03-11
11:35:33 UTC (rev 6679)
+++
trunk/ui/combobox/src/test/java/org/richfaces/renderkit/ComboBoxRendererTest.java 2008-03-11
12:23:57 UTC (rev 6680)
@@ -5,14 +5,12 @@
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.HashSet;
import java.util.List;
-import java.util.Set;
+import java.util.Map;
import javax.faces.component.UIComponent;
import javax.faces.component.UISelectItem;
import javax.faces.component.UISelectItems;
-import javax.faces.component.UISelectOne;
import javax.faces.model.SelectItem;
import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
@@ -21,7 +19,6 @@
import com.gargoylesoftware.htmlunit.html.HtmlElement;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
-import com.gargoylesoftware.htmlunit.html.HtmlSelect;
/**
* @author Anton Belevich
@@ -69,8 +66,11 @@
UISelectItems items = new UISelectItems();
items.setValue(selectItems);
- facesContext.getViewRoot().getChildren().add(comboBox);
-
+ facesContext.getViewRoot().getChildren().add(comboBox);
+
+ Map requestMap = facesContext.getExternalContext().getRequestParameterMap();
+ String id = "comboBoxValue" + comboBox.getClientId(facesContext);
+ requestMap.put(id, "Pennsylvania");
}
public void itemsTextAsJSArrayTest() {
@@ -82,7 +82,7 @@
HtmlPage page = renderView();
assertNotNull(page);
- HtmlElement elem = page.getHtmlElementById("control"+
comboBox.getClientId(facesContext));
+ HtmlElement elem = page.getHtmlElementById(comboBox.getClientId(facesContext));
assertNotNull(elem);
assertEquals(elem.getTagName(), "div");
}
@@ -93,8 +93,6 @@
renderer = null;
}
-
-
public ComboBoxRendererTest(String name) {
super(name);
}