Author: abelevich
Date: 2010-09-14 13:05:21 -0400 (Tue, 14 Sep 2010)
New Revision: 19202
Modified:
branches/RF-8992/ui/input/ui/src/main/java/org/richfaces/renderkit/InplaceInputBaseRenderer.java
branches/RF-8992/ui/input/ui/src/main/java/org/richfaces/renderkit/InplaceSelectBaseRenderer.java
branches/RF-8992/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/inplaceSelect.js
branches/RF-8992/ui/input/ui/src/main/templates/inplaceInput.template.xml
branches/RF-8992/ui/input/ui/src/main/templates/inplaceSelect.template.xml
Log:
add select functionality
Modified:
branches/RF-8992/ui/input/ui/src/main/java/org/richfaces/renderkit/InplaceInputBaseRenderer.java
===================================================================
---
branches/RF-8992/ui/input/ui/src/main/java/org/richfaces/renderkit/InplaceInputBaseRenderer.java 2010-09-14
16:27:08 UTC (rev 19201)
+++
branches/RF-8992/ui/input/ui/src/main/java/org/richfaces/renderkit/InplaceInputBaseRenderer.java 2010-09-14
17:05:21 UTC (rev 19202)
@@ -160,7 +160,7 @@
return result;
}
- public void buildScript(ResponseWriter writer, FacesContext facesContext, UIComponent
component) throws IOException {
+ public void buildScript(ResponseWriter writer, FacesContext facesContext, UIComponent
component, Object additional) throws IOException {
if(!(component instanceof InplaceComponent)) {
return;
}
@@ -169,7 +169,7 @@
JSFunction function = new JSFunction(scriptName);
String clientId = component.getClientId(facesContext);
Map<String, Object> options = createInplaceComponentOptions(clientId,
(InplaceComponent)component);
- addToOptions(facesContext, component, options);
+ addToOptions(facesContext, component, options, additional);
function.addParameter(clientId);
function.addParameter(options);
writer.write(function.toString());
@@ -200,7 +200,7 @@
return options;
}
- public void addToOptions(FacesContext facesContext, UIComponent component,
Map<String, Object> options) {
+ public void addToOptions(FacesContext facesContext, UIComponent component,
Map<String, Object> options, Object additional) {
//override this method if you need additional options
}
Modified:
branches/RF-8992/ui/input/ui/src/main/java/org/richfaces/renderkit/InplaceSelectBaseRenderer.java
===================================================================
---
branches/RF-8992/ui/input/ui/src/main/java/org/richfaces/renderkit/InplaceSelectBaseRenderer.java 2010-09-14
16:27:08 UTC (rev 19201)
+++
branches/RF-8992/ui/input/ui/src/main/java/org/richfaces/renderkit/InplaceSelectBaseRenderer.java 2010-09-14
17:05:21 UTC (rev 19202)
@@ -46,17 +46,38 @@
public static final String OPTIONS_LIST_CORD = "listCord";
public static final String OPTIONS_ITEMS_CORD = "itemsCord";
+
+ public static final String OPTIONS_SELECT_ITEMS = "selectItems";
+
+ public static final String OPTIONS_SELECT_ITEM_VALUE_INPUT =
"selValueInput";
+
protected static final class ClientSelectItem implements ScriptString {
- private String label;
+
+ private String clientId;
+ private String label;
private String convertedValue;
public ClientSelectItem(String convertedValue, String label) {
- super();
+ this(convertedValue, label, null);
+ }
+
+ public ClientSelectItem(String convertedValue, String label, String clientId) {
+ super();
this.convertedValue = convertedValue;
this.label = label;
+ this.clientId = clientId;
}
+
+ public String getClientId() {
+ return clientId;
+ }
+
+ public void setClientId(String clientId) {
+ this.clientId = clientId;
+ }
+
public String getLabel() {
return label;
}
@@ -68,9 +89,9 @@
public void appendScript(StringBuffer functionString) {
functionString.append(this.toScript());
}
-
+
public String toScript() {
- return "[" + ScriptUtils.toScript(label) + ", " +
ScriptUtils.toScript(convertedValue) + "]";
+ return "{ 'id' : " + ScriptUtils.toScript(clientId) + " ,
'label' : " + ScriptUtils.toScript(label) + ", 'value' : "
+ ScriptUtils.toScript(convertedValue) + "}";
}
}
@@ -92,24 +113,31 @@
}
@Override
- public void addToOptions(FacesContext facesContext, UIComponent component,
Map<String, Object> options) {
+ public void addToOptions(FacesContext facesContext, UIComponent component,
Map<String, Object> options, Object additional) {
options.put(OPTIONS_ITEM_CLASS, "insel_option");
options.put(OPTIONS_SELECT_ITEM_CLASS, "insel_select");
String clientId = component.getClientId(facesContext);
options.put(OPTIONS_LIST_CORD, clientId + "List");
options.put(OPTIONS_ITEMS_CORD, clientId + "Items");
+ options.put(OPTIONS_SELECT_ITEMS, additional);
+ options.put(OPTIONS_SELECT_ITEM_VALUE_INPUT, clientId + "selValue");
}
public void encodeOptions(FacesContext facesContext, UIComponent component,
List<ClientSelectItem> clientSelectItems) throws IOException {
AbstractInplaceSelect inplaceSelect = (AbstractInplaceSelect)component;
if(clientSelectItems != null && !clientSelectItems.isEmpty()) {
ResponseWriter writer = facesContext.getResponseWriter();
+ String clientId = component.getClientId(facesContext);
+ int i = 0;
for(ClientSelectItem clientSelectItem: clientSelectItems) {
- writer.startElement(HTML.SPAN_ELEM, inplaceSelect);
+ String itemClientId = clientId + "Item" + (i++);
+ clientSelectItem.setClientId(itemClientId);
+
+ writer.startElement(HTML.SPAN_ELEM, inplaceSelect);
+ writer.writeAttribute(HTML.ID_ATTRIBUTE, itemClientId, null);
writer.writeAttribute(HTML.CLASS_ATTRIBUTE, getOptionCss() , null);
String label = clientSelectItem.getLabel();
-
if(label != null && label.trim().length() > 0) {
writer.writeText(label, null);
} else {
@@ -120,6 +148,33 @@
}
}
+ public String getSelectLabel(FacesContext facesContext, UIComponent component) {
+ AbstractInplaceSelect select = (AbstractInplaceSelect)component;
+ String label = getSelectInputLabel(facesContext, select);
+ if(label == null) {
+ label = select.getDefaultLabel();
+ }
+ return label;
+ }
+
+ public String getSelectInputLabel(FacesContext facesContext, UIComponent component)
{
+ AbstractInplaceSelect select = (AbstractInplaceSelect)component;
+ Object value = select.getSubmittedValue();
+ if(value == null) {
+ value = select.getValue();
+ if(value != null) {
+ List<SelectItem> items = SelectUtils.getSelectItems(facesContext,
component);
+ for(SelectItem item: items) {
+ if(value.equals(item.getValue())) {
+ value = item.getLabel();
+ }
+ }
+ }
+ }
+
+ return (String)value;
+ }
+
public String getListStyles(FacesContext facesContext, UIComponent component) {
return "";
}
Modified:
branches/RF-8992/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/inplaceSelect.js
===================================================================
---
branches/RF-8992/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/inplaceSelect.js 2010-09-14
16:27:08 UTC (rev 19201)
+++
branches/RF-8992/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/inplaceSelect.js 2010-09-14
17:05:21 UTC (rev 19202)
@@ -5,6 +5,8 @@
rf.ui.InplaceSelect = function(id, options) {
$super.constructor.call(this, id, options)
this.select = new rf.ui.Select(options.listCord, this, options);
+ this.selectItems = options.selectItems;
+ this.selValueInput = $(document.getElementById(options.selValueInput));
}
rf.ui.InplaceInput.extend(rf.ui.InplaceSelect);
@@ -18,7 +20,7 @@
return{
name : "inplaceSelect",
- geName: function() {
+ getName: function() {
return this.name;
},
@@ -42,15 +44,41 @@
},
processItem: function(event, element) {
- var key = element.text();
- this.setValue(key);
+ var key = element.attr("id");
+ var value = this.getItemValue(key);
+ this.saveItemValue(value);
+
+ var label = this.getItemLabel(key);
+ //inplace label
+ this.setValue(label);
this.save();
},
+ getItemValue: function(key) {
+ for(var i in this.selectItems) {
+ var item = this.selectItems[i];
+ if(item && item.id == key) {
+ return item.value;
+ }
+ }
+ },
+
+ saveItemValue: function(value) {
+ this.selValueInput.val(value);
+ },
+
+ getItemLabel: function(key) {
+ for(var i in this.selectItems) {
+ var item = this.selectItems[i];
+ if(item && item.id == key) {
+ return item.label;
+ }
+ }
+ },
+
__blurHandler: function(e) {
return false;
}
-
}
})());
Modified: branches/RF-8992/ui/input/ui/src/main/templates/inplaceInput.template.xml
===================================================================
--- branches/RF-8992/ui/input/ui/src/main/templates/inplaceInput.template.xml 2010-09-14
16:27:08 UTC (rev 19201)
+++ branches/RF-8992/ui/input/ui/src/main/templates/inplaceInput.template.xml 2010-09-14
17:05:21 UTC (rev 19202)
@@ -80,7 +80,7 @@
</c:if>
</span>
<script type="text/javascript">
- <cdk:call expression="buildScript(responseWriter, facesContext,
component);"/>
+ <cdk:call expression="buildScript(responseWriter, facesContext, component,
null);"/>
</script>
</span>
</cc:implementation>
Modified: branches/RF-8992/ui/input/ui/src/main/templates/inplaceSelect.template.xml
===================================================================
--- branches/RF-8992/ui/input/ui/src/main/templates/inplaceSelect.template.xml 2010-09-14
16:27:08 UTC (rev 19201)
+++ branches/RF-8992/ui/input/ui/src/main/templates/inplaceSelect.template.xml 2010-09-14
17:05:21 UTC (rev 19202)
@@ -32,7 +32,7 @@
<cdk:object type="org.richfaces.component.InplaceState"
name="inplaceState" value="#{getInplaceState(component)}" />
<cdk:object type="java.lang.String" name="inplaceValue"
- value="#{getValue(facesContext, component)}" />
+ value="#{getSelectLabel(facesContext, component)}"/>
<cdk:object type="java.util.List"
type-arguments="InplaceSelectBaseRenderer.ClientSelectItem"
name="clientSelectItems"
value="#{getConvertedSelectItems(facesContext, component)}" />
@@ -47,8 +47,9 @@
<input id="#{clientId}:focus" type="image"
style="position: absolute; top: 0px; left: 0px; outline-style: none;"
class="rf-is-none" />
<span id="#{clientId}:edit" class="#{getEditStyleClass(component,
inplaceState)}">
- <input id="#{clientId}:input" autocomplete="off"
name="#{clientId}"
- type="text" value="#{getInputValue(facesContext, component)}"
+ <input id="#{clientId}selValue" name="#{clientId}"
type="hidden" value="#{getValue(facesContext, component)}"/>
+ <input id="#{clientId}:input" autocomplete="off"
+ type="text" value="#{getSelectInputLabel(facesContext,
component)}"
class="insel_field" style="width:
#{component.attributes['inputWidth']};" readonly="readonly"
cdk:passThrough="tabIndex">
<cdk:call expression="renderInputHandlers(facesContext, component);"
/>
@@ -95,7 +96,7 @@
</span>
</span>
<script type="text/javascript">
- <cdk:call expression="buildScript(responseWriter, facesContext,
component);" />
+ <cdk:call expression="buildScript(responseWriter, facesContext, component,
clientSelectItems);" />
</script>
</span>
</cc:implementation>