Author: abelevich
Date: 2008-04-11 05:44:49 -0400 (Fri, 11 Apr 2008)
New Revision: 7751
Modified:
trunk/ui/inplaceSelect/src/main/java/org/richfaces/component/UIInplaceSelect.java
trunk/ui/inplaceSelect/src/main/java/org/richfaces/renderkit/InplaceSelectBaseRenderer.java
trunk/ui/inplaceSelect/src/main/resources/org/richfaces/renderkit/html/css/inplaceselect.xcss
trunk/ui/inplaceSelect/src/main/templates/inplaceselect.jspx
Log:
applying review
Modified:
trunk/ui/inplaceSelect/src/main/java/org/richfaces/component/UIInplaceSelect.java
===================================================================
---
trunk/ui/inplaceSelect/src/main/java/org/richfaces/component/UIInplaceSelect.java 2008-04-11
09:21:26 UTC (rev 7750)
+++
trunk/ui/inplaceSelect/src/main/java/org/richfaces/component/UIInplaceSelect.java 2008-04-11
09:44:49 UTC (rev 7751)
@@ -1,27 +1,15 @@
package org.richfaces.component;
-import java.util.List;
-
-import javax.faces.component.UIComponent;
import javax.faces.component.UISelectOne;
-import javax.faces.context.FacesContext;
-import javax.faces.model.SelectItem;
-import org.ajax4jsf.util.SelectUtils;
-
/**
- * UI implementation of ComboBox component
+ * UI implementation of InplaceSelect component
* TODO: description here
* @author Anton Belevich
* @since 3.2.0
*
*/
-public class UIInplaceSelect extends UISelectOne{
-
- //TODO: Abstract class?
-
- //TODO: remove
- public List<SelectItem> getSelectItems(FacesContext context, UIComponent
component) {
- return SelectUtils.getSelectItems(context, component);
- }
+public abstract class UIInplaceSelect extends UISelectOne{
+ public static final String COMPONENT_TYPE = "org.richfaces.InplaceSelect";
+ final static public String COMPONENT_FAMILY =
"org.richfaces.InplaceSelect";
}
Modified:
trunk/ui/inplaceSelect/src/main/java/org/richfaces/renderkit/InplaceSelectBaseRenderer.java
===================================================================
---
trunk/ui/inplaceSelect/src/main/java/org/richfaces/renderkit/InplaceSelectBaseRenderer.java 2008-04-11
09:21:26 UTC (rev 7750)
+++
trunk/ui/inplaceSelect/src/main/java/org/richfaces/renderkit/InplaceSelectBaseRenderer.java 2008-04-11
09:44:49 UTC (rev 7751)
@@ -5,7 +5,6 @@
import java.io.IOException;
import java.util.ArrayList;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -33,149 +32,123 @@
private static final String CONTROLS_FACET = "controls";
private static final String EMPTY_DEFAULT_LABEL =
"   ";
- //Check copyPaste
@Override
protected void doDecode(FacesContext context, UIComponent component) {
- UIInplaceSelect inplaceInput = null;
+ UIInplaceSelect inplaceSelect = null;
+
+ if (component instanceof UIInplaceSelect) {
+ inplaceSelect = (UIInplaceSelect) component;
+ } else {
+ if (logger.isDebugEnabled()) {
+ logger.debug("No decoding necessary since the component " +
component.getId()
+ + " is not an instance or a sub class of UIInplaceSelect");
+ }
+ return;
+ }
- if (component instanceof UIInplaceSelect) {
- inplaceInput = (UIInplaceSelect) component;
- } else {
- if (logger.isDebugEnabled()) {
- logger.debug("No decoding necessary since the component " +
component.getId() + " is not an instance or a sub class of UIInplaceSelect");
- }
- return;
- }
+ String clientId = inplaceSelect.getClientId(context);
+ if (clientId == null) {
+ throw new NullPointerException("component client id is NULL");
+ }
+
+ if (InputUtils.isDisabled(inplaceSelect) || InputUtils.isReadOnly(inplaceSelect)) {
+ if (logger.isDebugEnabled()) {
+ logger.debug(("No decoding necessary since the component " +
component.getId() + " is disabled"));
+ }
+ return;
+ }
- if (InputUtils.isDisabled(inplaceInput) || InputUtils.isReadOnly(inplaceInput)) {
- 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 " +
inplaceInput.getClientId(context) + " client id is NULL");
- }
-
- clientId = clientId + "inplaceValue";
- Map request = context.getExternalContext().getRequestParameterMap();
- if (request.containsKey(clientId)) {
- String newValue = (String) request.get(clientId);
- if(newValue != null) {
- inplaceInput.setSubmittedValue(newValue);
- }
- }
+ Map <String,String> request =
context.getExternalContext().getRequestParameterMap();
+ String newValue = (String) request.get(clientId);
+ if (newValue != null) {
+ inplaceSelect.setSubmittedValue(newValue);
+ }
}
- //TODO: base on super method:
- //return component != null ?
this.getComponentClass().isAssignableFrom(component.getClass()) : false;
- protected boolean isAcceptableComponent(UIComponent component) {
- if (component instanceof UIInplaceSelect) {
- return true;
- }
- return false;
+ public List<Object> encodeItems(FacesContext context, UIComponent component)
throws IOException, IllegalArgumentException {
+
+ if (!isAcceptableComponent(component)) {
+ return null;
+ }
+
+ List<Object> parentList = new ArrayList<Object>();
+ List<String> labels = new ArrayList<String>();
+
+ UIInplaceSelect inplaceSelect = (UIInplaceSelect) component;
+ ResponseWriter writer = context.getResponseWriter();
+ List<SelectItem> selectItems = SelectUtils.getSelectItems(context,
inplaceSelect);
+ for (SelectItem selectItem : selectItems) {
+ String value = getConvertedStringValue(context, inplaceSelect,
selectItem.getValue());
+ String label = selectItem.getLabel();
+ labels.add(label);
+ encodeSuggestion(writer, inplaceSelect, label, RICH_INPLACE_SELECT_CLASSES);
+ Object[] child = new Object[2];
+ child[0] = label;
+ child[1] = value;
+ parentList.add(child);
+ }
+ return parentList;
}
-
- public List encodeItems(FacesContext context, UIComponent component) throws
IOException {
-
- if (!isAcceptableComponent(component)) {
- return null;
- }
-
- //TODO generify
- List parentList = new ArrayList();
- UIInplaceSelect inplaceSelect = (UIInplaceSelect)component;
- List <String> labels = new ArrayList<String>();
- ResponseWriter writer = context.getResponseWriter();
- List<SelectItem> selectItems = SelectUtils.getSelectItems(context,
inplaceSelect);
- //TODO use foreach
- if (!selectItems.isEmpty()) {
- for (Iterator<SelectItem> iterator = selectItems.iterator();
iterator.hasNext();) {
- SelectItem selectItem = iterator.next();
- String value = getConvertedStringValue(context, inplaceSelect,
selectItem.getValue());
- String label = selectItem.getLabel();
- labels.add(label);
-
- encodeSuggestion(writer, inplaceSelect, label, RICH_INPLACE_SELECT_CLASSES);
-
- //TODO: review
- List childList = new ArrayList(2); //new Object[2]
- childList.add(label);
- childList.add(value);
- parentList.add(childList);
- }
- }
- return parentList;
- }
public void encodeControlsFacet(FacesContext context, UIComponent component) throws
IOException {
- UIComponent facet = component.getFacet(CONTROLS_FACET);
- if ((facet != null) && (facet.isRendered())) {
- renderChild(context, facet);
- }
+ UIComponent facet = component.getFacet(CONTROLS_FACET);
+ if ((facet != null) && (facet.isRendered())) {
+ renderChild(context, facet);
+ }
}
public boolean isControlsFacetExists(FacesContext context, UIComponent component) {
- UIComponent facet = component.getFacet(CONTROLS_FACET);
- if (facet != null && facet.isRendered()) {
- return true;
- }
- return false;
+ UIComponent facet = component.getFacet(CONTROLS_FACET);
+ if (facet != null && facet.isRendered()) {
+ return true;
+ }
+ return false;
}
protected Class<? extends UIComponent> getComponentClass() {
return UIInplaceSelect.class;
}
- //TODO: review
public String getSelectedItemLabel(FacesContext context, UIInplaceSelect component)
{
- //TODO: submitted value should be converted before searching for label
- Object value = component.getSubmittedValue();
- if (value == null) {
- value = component.getAttributes().get("value");
- }
- if (value == null) {
- return createDefaultLabel(component);
- }
-
- String defaultLabel = getItemLabel(context, component, value);
- if (defaultLabel == null) {
- return createDefaultLabel(component);
- }
- return defaultLabel;
+ Object submittedValue = component.getSubmittedValue();
+ Object value = submittedValue != null ? getConvertedValue(context, component,
submittedValue) : component.getAttributes().get("value");
+ if (value == null || "".equals(value)) {
+ return createDefaultLabel(component);
+ }
+ return getItemLabel(context, component, value);
}
protected String getItemLabel(FacesContext context, UIComponent component, Object
value) {
- String itemLabel = null;
- //TODO: SelectUtils.getSelectItems is called minimum twice during encode
- List<SelectItem> selectItems = SelectUtils.getSelectItems(context, component);
- if (!selectItems.isEmpty()) {
- for(SelectItem item : selectItems) {
- if (value.equals(item.getValue())) {
- itemLabel = item.getLabel();
- //TODO break
- }
- }
+ String itemLabel = null;
+ // TODO: SelectUtils.getSelectItems is called minimum twice during
+ // encode
+ List<SelectItem> selectItems = SelectUtils.getSelectItems(context, component);
+ if (!selectItems.isEmpty()) {
+ for (SelectItem item : selectItems) {
+ if (value.equals(item.getValue())) {
+ itemLabel = item.getLabel();
+ break;
}
-
- //TODO exception if item hasn't been found
-
- return itemLabel;
+ }
+ }
+
+ if (itemLabel == null) {
+ throw new IllegalArgumentException("passed value is incorrect");
+ }
+
+ return itemLabel;
}
protected String createDefaultLabel(UIComponent component) {
- String defaultLabel = (String)
component.getAttributes().get("defaultLabel");
- //TODO use length()
- if (defaultLabel == null || defaultLabel.equals("")) {
- defaultLabel = EMPTY_DEFAULT_LABEL;
- }
- return defaultLabel;
+ String defaultLabel = (String) component.getAttributes().get("defaultLabel");
+ if (defaultLabel == null || defaultLabel.length() == 0) {
+ defaultLabel = EMPTY_DEFAULT_LABEL;
+ }
+ return defaultLabel;
}
protected boolean isEmptyDefaultLabel(String defaultLabel) {
- //TODO review
- if (defaultLabel != null && EMPTY_DEFAULT_LABEL.equals(defaultLabel)) {
+ if (EMPTY_DEFAULT_LABEL.equals(defaultLabel)) {
return true;
}
return false;
Modified:
trunk/ui/inplaceSelect/src/main/resources/org/richfaces/renderkit/html/css/inplaceselect.xcss
===================================================================
---
trunk/ui/inplaceSelect/src/main/resources/org/richfaces/renderkit/html/css/inplaceselect.xcss 2008-04-11
09:21:26 UTC (rev 7750)
+++
trunk/ui/inplaceSelect/src/main/resources/org/richfaces/renderkit/html/css/inplaceselect.xcss 2008-04-11
09:44:49 UTC (rev 7751)
@@ -232,30 +232,11 @@
<u:style name="border-color" skin="headerBackgroundColor" />
</u:selector>
- <u:selector name=".rich-inplace-select-shadow-tl">
+ <u:selector name=".rich-inplace-select-shadow-tl,
.rich-inplace-select-shadow-tr, .rich-inplace-select-shadow-bl ,
.rich-inplace-select-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-inplace-select-shadow-tr">
- <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-inplace-select-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-inplace-select-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-inplace-select-arrow">
<u:style name="background-image">
<f:resource
f:key="org.richfaces.renderkit.html.images.SpinnerButtonDown"/>
Modified: trunk/ui/inplaceSelect/src/main/templates/inplaceselect.jspx
===================================================================
--- trunk/ui/inplaceSelect/src/main/templates/inplaceselect.jspx 2008-04-11 09:21:26 UTC
(rev 7750)
+++ trunk/ui/inplaceSelect/src/main/templates/inplaceselect.jspx 2008-04-11 09:44:49 UTC
(rev 7751)
@@ -78,8 +78,7 @@
<jsp:scriptlet>
if (layout.equals("inline")) {
</jsp:scriptlet>
- <!-- TODO #{component.attributes['viewClass']} -->
- <span id="#{clientId}" class="rich-inplace-select
rich-inplace-select-view"
x:passThruWithExclusions="id,styleClass,class,style">
+ <span id="#{clientId}" class="rich-inplace-select
rich-inplace-select-view #{component.attributes['viewClass']}"
x:passThruWithExclusions="id,styleClass,class,style">
<jsp:scriptlet>
} else {
</jsp:scriptlet>
@@ -97,7 +96,7 @@
readonly="readonly"
class="rich-inplace-select-field"/>
<input id="#{clientId}inselArrow" readonly="readonly"
type="Text" value="" class="rich-inplace-select-arrow"
style='display:none;'/>
- <input id='#{clientId}inplaceValue' name='#{clientId}inplaceValue'
type='hidden' value='#{fieldValue}'/>
+ <input id='#{clientId}inplaceValue' name='#{clientId}'
type='hidden' value='#{fieldValue}'/>
<div id="#{clientId}bar" class="rich-inplace-select-control-set"
style="display:none;">
<jsp:scriptlet>
<![CDATA[
@@ -213,8 +212,8 @@
} else {
writer.writeText(convertToString(variables.getVariable("fieldLabel")),null);
}
- //TODO !layout.equals("inline")
- if (layout.equals("block")) {
+
+ if (!layout.equals("inline")) {
</jsp:scriptlet>
</div>
<jsp:scriptlet>