Author: abelevich
Date: 2008-04-08 10:16:32 -0400 (Tue, 08 Apr 2008)
New Revision: 7666
Modified:
branches/3.2.x/ui/inplaceSelect/src/main/java/org/richfaces/renderkit/InplaceSelectBaseRenderer.java
branches/3.2.x/ui/inplaceSelect/src/main/templates/inplaceselect.jspx
Log:
merge with trunk
http://jira.jboss.com/jira/browse/RF-2967
Modified:
branches/3.2.x/ui/inplaceSelect/src/main/java/org/richfaces/renderkit/InplaceSelectBaseRenderer.java
===================================================================
---
branches/3.2.x/ui/inplaceSelect/src/main/java/org/richfaces/renderkit/InplaceSelectBaseRenderer.java 2008-04-08
14:16:05 UTC (rev 7665)
+++
branches/3.2.x/ui/inplaceSelect/src/main/java/org/richfaces/renderkit/InplaceSelectBaseRenderer.java 2008-04-08
14:16:32 UTC (rev 7666)
@@ -19,7 +19,6 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.richfaces.component.UIInplaceSelect;
-import org.richfaces.json.JSONArray;
/**
* InplaceSelect base renderer implementation
@@ -31,127 +30,139 @@
private static Log logger = LogFactory.getLog(InplaceSelectBaseRenderer.class);
private static final String RICH_INPLACE_SELECT_CLASSES =
"rich-inplace-select-item rich-inplace-select-font";
private static final String CONTROLS_FACET = "controls";
+ private static final String EMPTY_DEFAULT_LABEL =
"   ";
+
- private JSONArray jsonParentArray;
-
-
@Override
protected void doDecode(FacesContext context, UIComponent component) {
- UIInplaceSelect inplaceInput = null;
-
- 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;
- }
-
- 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);
- }
- }
+ UIInplaceSelect inplaceInput = null;
+
+ 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;
+ }
+
+ 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);
+ }
+ }
}
- public void encodeItems(FacesContext context, UIComponent component) throws
IOException {
- List <String> labels = new ArrayList<String>();
- ResponseWriter writer = context.getResponseWriter();
- jsonParentArray = new JSONArray();
-
- 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, component, selectItem.getValue());
- String label = selectItem.getLabel();
- labels.add(label);
-
- encodeSuggestion(writer, component, label, RICH_INPLACE_SELECT_CLASSES);
-
- JSONArray jsonChildArray = new JSONArray();
- jsonChildArray.put(label);
- jsonChildArray.put(value);
- jsonParentArray.put(jsonChildArray);
- }
- }
- setValuesList(labels);
+ protected boolean isAcceptableComponent(UIComponent component) {
+ if (component instanceof UIInplaceSelect) {
+ return true;
+ }
+ return false;
}
+
+ public List encodeItems(FacesContext context, UIComponent component) throws
IOException {
+
+ if (!isAcceptableComponent(component)) {
+ return null;
+ }
+
+ 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);
+ 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);
+
+ List childList = new ArrayList();
+ 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;
+ return UIInplaceSelect.class;
}
- public String getItemsTextAsJSArray(FacesContext context, UIComponent component) {
- StringBuffer attributes = new StringBuffer();
- attributes.append(jsonParentArray.toString());
- return attributes.toString();
- }
-
public String getSelectedItemLabel(FacesContext context, UIInplaceSelect component)
{
- String defaultLabel = null;
- Object value = component.getSubmittedValue();
- if (value == null) {
- value = component.getAttributes().get("value");
- }
- if (value == null) {
- return createDefaultLabel(component);
- }
- defaultLabel = getItemLabel(context, component, value);
- if (defaultLabel == null) {
- return createDefaultLabel(component);
- }
- return defaultLabel;
+ String defaultLabel = null;
+ Object value = component.getSubmittedValue();
+ if (value == null) {
+ value = component.getAttributes().get("value");
+ }
+ if (value == null) {
+ return createDefaultLabel(component);
+ }
+ defaultLabel = getItemLabel(context, component, value);
+ if (defaultLabel == null) {
+ return createDefaultLabel(component);
+ }
+ return defaultLabel;
}
protected String getItemLabel(FacesContext context, UIComponent component, Object
value) {
- String itemLabel = null;
- List<SelectItem> selectItems = SelectUtils.getSelectItems(context, component);
- if (!selectItems.isEmpty()) {
- for(SelectItem item : selectItems) {
- if (value.equals(item.getValue())) {
- itemLabel = item.getLabel();
+ String itemLabel = null;
+ List<SelectItem> selectItems = SelectUtils.getSelectItems(context, component);
+ if (!selectItems.isEmpty()) {
+ for(SelectItem item : selectItems) {
+ if (value.equals(item.getValue())) {
+ itemLabel = item.getLabel();
+ }
+ }
}
- }
- }
- return itemLabel;
+ return itemLabel;
}
protected String createDefaultLabel(UIComponent component) {
- String defaultLabel = (String) component.getAttributes().get("defaultLabel");
- if (defaultLabel == null || defaultLabel.equals("")) {
- defaultLabel = "   ";
- }
- return defaultLabel;
+ String defaultLabel = (String)
component.getAttributes().get("defaultLabel");
+ if (defaultLabel == null || defaultLabel.equals("")) {
+ defaultLabel = EMPTY_DEFAULT_LABEL;
+ }
+ return defaultLabel;
}
+
+ protected boolean isEmptyDefaultLabel(String defaultLabel) {
+ if (defaultLabel != null && EMPTY_DEFAULT_LABEL.equals(defaultLabel)) {
+ return true;
+ }
+ return false;
+ }
}
Modified: branches/3.2.x/ui/inplaceSelect/src/main/templates/inplaceselect.jspx
===================================================================
--- branches/3.2.x/ui/inplaceSelect/src/main/templates/inplaceselect.jspx 2008-04-08
14:16:05 UTC (rev 7665)
+++ branches/3.2.x/ui/inplaceSelect/src/main/templates/inplaceselect.jspx 2008-04-08
14:16:32 UTC (rev 7666)
@@ -9,6 +9,8 @@
baseclass="org.richfaces.renderkit.InplaceSelectBaseRenderer"
class="org.richfaces.renderkit.html.InplaceSelectRenderer"
component="org.richfaces.component.UIInplaceSelect">
+
+
<h:styles>css/inplaceselect.xcss</h:styles>
@@ -32,10 +34,10 @@
if(value == null) {
value = component.getAttributes().get("value");
}
- Object fieldValue = value;
- String fieldLabel = getSelectedItemLabel(context, component);
+ String fieldLabel = getSelectedItemLabel(context, component);
value = getConvertedStringValue(context, component,value);
-
+ Object fieldValue = value;
+
if (value == null || value.equals("")) {
fieldValue = "";
}
@@ -158,7 +160,8 @@
<div id="listPosition#{clientId}"
class="rich-inplace-select-list-position">
<div id="listDecoration#{clientId}"
class="rich-inplace-select-list-decoration">
<div id="list#{clientId}"
class="rich-inplace-select-list-scroll">
- <f:call name="encodeItems"/>
+ <c:object type="java.util.List" var="items"
value="#{this:encodeItems(context,component)}">
+ </c:object>
</div>
</div>
</div>
@@ -179,7 +182,7 @@
};
new Richfaces.InplaceSelect(new
Richfaces.InplaceSelectList('list#{clientId}', 'listParent#{clientId}',
true,
- Richfaces.InplaceSelect.CLASSES.COMBO_LIST,
'#{component.attributes["listWidth"]}',
'#{component.attributes["listHeight"]}',
#{this:getItemsTextAsJSArray(context, component)}, null,
+ Richfaces.InplaceSelect.CLASSES.COMBO_LIST,
'#{component.attributes["listWidth"]}',
'#{component.attributes["listHeight"]}',
#{this:getItemsTextAsJSArray(context, component,items)}, null,
'#{clientId}inplaceTmpValue',
'shadow#{clientId}', 0, 0, '#{fieldValue}'),
'#{clientId}', '#{clientId}inplaceTmpValue',
'#{clientId}inplaceValue', '#{clientId}tabber',
@@ -191,7 +194,8 @@
inputWidth :
'#{component.attributes["selectWidth"]}',
minInputWidth :
'#{component.attributes["minSelectWidth"]}',
maxInputWidth :
'#{component.attributes["maxSelectWidth"]}',
- openOnEdit:#{component.attributes["openOnEdit"]}},
+ openOnEdit: #{component.attributes["openOnEdit"]},
+ closeOnSelect: true},
{oneditactivation : #{this:getAsEventHandler(context, component,
"oneditactivation")},
onviewactivation : #{this:getAsEventHandler(context, component,
"onviewactivation")},
oneditactivated : #{this:getAsEventHandler(context, component,
"oneditactivated")},
@@ -202,7 +206,11 @@
</div>
<jsp:scriptlet>
- writer.write(convertToString(variables.getVariable("fieldLabel")));
+ if(isEmptyDefaultLabel(convertToString(variables.getVariable("fieldLabel"))))
{
+ writer.write(convertToString(variables.getVariable("fieldLabel")));
+ } else {
+ writer.writeText(convertToString(variables.getVariable("fieldLabel")),null);
+ }
if (layout.equals("block")) {
</jsp:scriptlet>
</div>