Author: vmolotkov
Date: 2008-03-25 15:17:31 -0400 (Tue, 25 Mar 2008)
New Revision: 7233
Modified:
trunk/ui/inplaceSelect/src/main/java/org/richfaces/renderkit/InplaceSelectBaseRenderer.java
trunk/ui/inplaceSelect/src/main/resources/org/richfaces/renderkit/html/scripts/inplaceselect.js
trunk/ui/inplaceSelect/src/main/resources/org/richfaces/renderkit/html/scripts/inplaceselectlist.js
trunk/ui/inplaceSelect/src/main/templates/inplaceselect.jspx
Log:
RF-2683: inplaceSelect should be selectOne
Modified:
trunk/ui/inplaceSelect/src/main/java/org/richfaces/renderkit/InplaceSelectBaseRenderer.java
===================================================================
---
trunk/ui/inplaceSelect/src/main/java/org/richfaces/renderkit/InplaceSelectBaseRenderer.java 2008-03-25
19:04:36 UTC (rev 7232)
+++
trunk/ui/inplaceSelect/src/main/java/org/richfaces/renderkit/InplaceSelectBaseRenderer.java 2008-03-25
19:17:31 UTC (rev 7233)
@@ -32,6 +32,8 @@
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 JSONArray jsonParentArray;
@Override
@@ -69,7 +71,7 @@
public void encodeItems(FacesContext context, UIComponent component) throws
IOException {
List <String> labels = new ArrayList<String>();
ResponseWriter writer = context.getResponseWriter();
- JSONArray jsonParentArray = new JSONArray();
+ jsonParentArray = new JSONArray();
List<SelectItem> selectItems = SelectUtils.getSelectItems(context, component);
if (!selectItems.isEmpty()) {
@@ -88,14 +90,6 @@
}
}
setValuesList(labels);
- StringBuffer attributes = new StringBuffer();
- writer.startElement("script", component);
- getUtils().writeAttribute(writer, "type", "text/javascript" );
- attributes.append("var options = ");
- attributes.append(jsonParentArray.toString());
- attributes.append(";");
- writer.write(attributes.toString());
- writer.endElement("script");
}
public void encodeControlsFacet(FacesContext context, UIComponent component) throws
IOException {
@@ -116,4 +110,44 @@
protected Class<? extends UIComponent> getComponentClass() {
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, UIComponent component) {
+ String defaultLabel = null;
+ Object 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();
+ }
+ }
+ }
+ return itemLabel;
+ }
+
+ protected String createDefaultLabel(UIComponent component) {
+ String defaultLabel = (String) component.getAttributes().get("defaultLabel");
+ if (defaultLabel == null || defaultLabel.equals("")) {
+ defaultLabel = "\u00a0\u00a0\u00a0";
+ }
+ return defaultLabel;
+ }
}
Modified:
trunk/ui/inplaceSelect/src/main/resources/org/richfaces/renderkit/html/scripts/inplaceselect.js
===================================================================
---
trunk/ui/inplaceSelect/src/main/resources/org/richfaces/renderkit/html/scripts/inplaceselect.js 2008-03-25
19:04:36 UTC (rev 7232)
+++
trunk/ui/inplaceSelect/src/main/resources/org/richfaces/renderkit/html/scripts/inplaceselect.js 2008-03-25
19:17:31 UTC (rev 7233)
@@ -1,11 +1,12 @@
if(!window.Richfaces) window.Richfaces = {};
Richfaces.InplaceSelect = Class.create(Richfaces.InplaceInput, {
initialize : function($super, listObj, clientId, temValueKeepId, valueKeepId, tabberId,
attributes, events, classes, barParams, buttonId) {
+ this.button = $(buttonId);
this.comboList = listObj;
- this.button = $(buttonId);
$super(clientId, temValueKeepId, valueKeepId, tabberId, attributes, events, classes,
barParams);
this.clickOnBar = false;
+ this.currentItemValue = this.value;
this.button.style.top = Richfaces.getBorderWidth(this.tempValueKeeper, "t") +
"px";
},
@@ -70,7 +71,7 @@
this.comboList.hideWithDelay();
}
if (this.attributes.showControls) {
- this.save();
+ this.saveValue();
}
this.comboList.isList = false;
/*this.comboList.hideWithDelay();*/
@@ -108,7 +109,7 @@
tmpValueKeyDownHandlerIn : function(event) {
switch (event.keyCode) {
case Event.KEY_RETURN :
- this.save();
+ this.saveValue();
this.comboList.hideWithDelay();
Event.stop(event);
break;
@@ -126,15 +127,16 @@
}
},
- save : function($super) {
+ saveValue : function($super) {
if (this.comboList.activeItem) {
- var userValue = this.comboList.activeItem.innerHTML;
- this.tempValueKeeper.value = userValue;
+ var userLabel = this.comboList.activeItem.innerHTML;
+ this.currentItemValue = this.comboList.activeItem.value;
+ this.tempValueKeeper.value = userLabel;
this.comboList.selectedItem = this.comboList.activeItem;
//this.clickOnField = false;
}
if (!this.comboList.isList || this.clickOnBar) {
- $super();
+ this.save(this.currentItemValue, this.tempValueKeeper.value);
}
},
Modified:
trunk/ui/inplaceSelect/src/main/resources/org/richfaces/renderkit/html/scripts/inplaceselectlist.js
===================================================================
---
trunk/ui/inplaceSelect/src/main/resources/org/richfaces/renderkit/html/scripts/inplaceselectlist.js 2008-03-25
19:04:36 UTC (rev 7232)
+++
trunk/ui/inplaceSelect/src/main/resources/org/richfaces/renderkit/html/scripts/inplaceselectlist.js 2008-03-25
19:17:31 UTC (rev 7233)
@@ -1,7 +1,8 @@
if(!window.Richfaces) window.Richfaces = {};
Richfaces.InplaceSelectList = Class.create(Richfaces.ComboBoxList, {
- initialize : function($super, listId, parentListId, selectFirstOnUpdate, classes, width,
height, itemsText, onlistcall, fieldId, shadowId, showDelay, hideDelay) {
+ initialize : function($super, listId, parentListId, selectFirstOnUpdate, classes, width,
height, itemsText, onlistcall, fieldId, shadowId, showDelay, hideDelay, value) {
$super(listId, parentListId, selectFirstOnUpdate, classes, width, height, itemsText,
onlistcall, fieldId, shadowId, showDelay, hideDelay);
+ this.wrappingItems(value);
},
setPosition : function($super, fieldTop, fieldLeft, fieldHeight) {
@@ -35,11 +36,7 @@
},
resetState : function() {
- //var tempList = this.list.cloneNode(false);
- //this.listParent.childNodes[1].firstChild.replaceChild(tempList, this.list);
- //this.list = $(tempList.id);
this.activeItem = null;
- //this.isList = false;
},
getEventItem : function(event) {
@@ -68,5 +65,16 @@
}
var component = this.listParent.parentNode;
this.listParent.hide();
+ },
+
+ wrappingItems : function(value) {
+ var len = this.getItems().length;
+ for (var i = 0; i < len; i++) {
+ var it = this.getItems()[i];
+ it.value = this.itemsText[i][1];
+ if (it.value == value) {
+ this.doSelectItem(it);
+ }
+ }
}
});
Modified: trunk/ui/inplaceSelect/src/main/templates/inplaceselect.jspx
===================================================================
--- trunk/ui/inplaceSelect/src/main/templates/inplaceselect.jspx 2008-03-25 19:04:36 UTC
(rev 7232)
+++ trunk/ui/inplaceSelect/src/main/templates/inplaceselect.jspx 2008-03-25 19:17:31 UTC
(rev 7233)
@@ -29,17 +29,13 @@
<![CDATA[
Object value = component.getAttributes().get("value");
Object fieldValue = component.getAttributes().get("value");
+ String fieldLabel = getSelectedItemLabel(context, component);
value = getConvertedStringValue(context, component,value);
if (value == null || value.equals("")) {
fieldValue = "";
- String defaultValue =
(String)component.getAttributes().get("defaultLabel");
- if(defaultValue == null || defaultValue.equals("")) {
- defaultValue = "\u00a0\u00a0\u00a0";
- }
- value = defaultValue;
}
- variables.setVariable("value", value);
+ variables.setVariable("fieldLabel", fieldLabel);
variables.setVariable("fieldValue", fieldValue);
/*String saveIcon =
(String)component.getAttributes().get("saveControlIcon");
@@ -88,7 +84,7 @@
<input id="#{clientId}inplaceTmpValue"
type="text"
style='display:none;'
- value="#{fieldValue}"
+ value="#{fieldLabel}"
autocomplete="off"
maxlength='#{component.attributes["inputMaxLength"]}'
readonly="readonly"
@@ -178,32 +174,29 @@
}
};
- var richInplaceSelAttributes = {defaultLabel :
'#{component.attributes["defaultLabel"]}',
- showControls : #{component.attributes["showControls"]},
- editEvent : '#{component.attributes["editEvent"]}',
- verticalPosition :
'#{component.attributes["controlsVerticalPosition"]}',
- horizontalPosition :
'#{component.attributes["controlsHorizontalPosition"]}',
- inputWidth : '#{component.attributes["selectWidth"]}',
- minInputWidth : '#{component.attributes["minSelectWidth"]}',
- maxInputWidth : '#{component.attributes["maxSelectWidth"]}',
- openOnEdit:#{component.attributes["openOnEdit"]}
- };
-
- var richInplaceSelEvents = {oneditactivation : #{this:getAsEventHandler(context,
component, "oneditactivation")},
- onviewactivation : #{this:getAsEventHandler(context, component,
"onviewactivation")},
- oneditactivated : #{this:getAsEventHandler(context, component,
"oneditactivated")},
- onviewactivated : #{this:getAsEventHandler(context, component,
"onviewactivated")}};
-
- var richInplaceList = new Richfaces.InplaceSelectList('list#{clientId}',
'listParent#{clientId}', true,
- Richfaces.InplaceSelect.CLASSES.COMBO_LIST,
'#{component.attributes["listWidth"]}',
'#{component.attributes["listHeight"]}', options, null,
- '#{clientId}inplaceTmpValue', 'shadow#{clientId}', 0,
0);
- var richInplaceSelect = new Richfaces.InplaceSelect(richInplaceList,
'#{clientId}', '#{clientId}inplaceTmpValue',
+ 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,
+ '#{clientId}inplaceTmpValue',
'shadow#{clientId}', 0, 0, '#{fieldValue}'),
+ '#{clientId}', '#{clientId}inplaceTmpValue',
'#{clientId}inplaceValue', '#{clientId}tabber',
- richInplaceSelAttributes, richInplaceSelEvents,
Richfaces.InplaceSelect.CLASSES,
+ {defaultLabel :
'#{component.attributes["defaultLabel"]}',
+ showControls : #{component.attributes["showControls"]},
+ editEvent : '#{component.attributes["editEvent"]}',
+ verticalPosition :
'#{component.attributes["controlsVerticalPosition"]}',
+ horizontalPosition :
'#{component.attributes["controlsHorizontalPosition"]}',
+ inputWidth :
'#{component.attributes["selectWidth"]}',
+ minInputWidth :
'#{component.attributes["minSelectWidth"]}',
+ maxInputWidth :
'#{component.attributes["maxSelectWidth"]}',
+ openOnEdit:#{component.attributes["openOnEdit"]}},
+ {oneditactivation : #{this:getAsEventHandler(context, component,
"oneditactivation")},
+ onviewactivation : #{this:getAsEventHandler(context, component,
"onviewactivation")},
+ oneditactivated : #{this:getAsEventHandler(context, component,
"oneditactivated")},
+ onviewactivated : #{this:getAsEventHandler(context, component,
"onviewactivated")}},
+ Richfaces.InplaceSelect.CLASSES,
['#{clientId}bar', '#{clientId}ok',
'#{clientId}cancel', '#{clientId}buttons',
'#{clientId}btns_shadow'], '#{clientId}inselArrow');
</script>
</div>
- #{value}
+ #{fieldLabel}
<jsp:scriptlet>