Author: abelevich
Date: 2010-08-31 08:35:45 -0400 (Tue, 31 Aug 2010)
New Revision: 19037
Modified:
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/InplaceInputBaseRenderer.java
trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/inplaceInput.js
trunk/ui/input/ui/src/main/templates/inplaceInput.template.xml
Log:
add defaultLabel func
Modified:
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/InplaceInputBaseRenderer.java
===================================================================
---
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/InplaceInputBaseRenderer.java 2010-08-31
12:14:40 UTC (rev 19036)
+++
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/InplaceInputBaseRenderer.java 2010-08-31
12:35:45 UTC (rev 19037)
@@ -35,7 +35,6 @@
import javax.faces.context.ResponseWriter;
import org.ajax4jsf.javascript.JSFunction;
-import org.ajax4jsf.renderkit.RendererBase;
import org.ajax4jsf.renderkit.RendererUtils.HTML;
import org.richfaces.component.AbstractInplaceInput;
import org.richfaces.component.InplaceState;
@@ -51,7 +50,7 @@
@ResourceDependency(name = "richfaces-base-component.js"),
@ResourceDependency(library="org.richfaces", name =
"inplaceInput.js"),
@ResourceDependency(library="org.richfaces", name =
"inplaceInput.ecss") })
-public class InplaceInputBaseRenderer extends RendererBase {
+public class InplaceInputBaseRenderer extends InputRendererBase {
public static final String OPTIONS_EDIT_EVENT = "editEvent";
@@ -61,12 +60,14 @@
public static final String OPTIONS_FOCUS = "focusElement";
- public static final String OPTIONS_BTN_OK = "okbtn";
+ public static final String OPTIONS_BUTTON_OK = "okbtn";
public static final String OPTIONS_LABEL = "label";
- public static final String OPTIONS_BTN_CANCEL = "cancelbtn";
+ public static final String OPTIONS_DEFAULT_LABEL = "defaultLabel";
+ public static final String OPTIONS_BUTTON_CANCEL = "cancelbtn";
+
public static final String OPTIONS_SHOWCONTROLS = "showControls";
public static final String OPTIONS_NONE_CSS = "noneCss";
@@ -115,17 +116,6 @@
setComponentAttributeName("onselect")
));
-
- @Override
- protected void doDecode(FacesContext facesContext, UIComponent component) {
- AbstractInplaceInput inplaceInput = (AbstractInplaceInput)component;
- Map <String, String> parameterMap =
facesContext.getExternalContext().getRequestParameterMap();
- String newValue =
(String)parameterMap.get(inplaceInput.getClientId(facesContext));
- if (newValue != null) {
- inplaceInput.setSubmittedValue(newValue);
- }
- }
-
protected void renderInputHandlers(FacesContext facesContext, UIComponent component)
throws IOException {
RenderKitUtils.renderPassThroughAttributesOptimized(facesContext, component,
INPLACEINPUT_HANDLER_ATTRIBUTES);
}
@@ -134,12 +124,15 @@
return ((AbstractInplaceInput) component).getState();
}
- public String getValue(FacesContext context, UIComponent component) throws
IOException {
- // TODO: convert?
- String value = (String) ((AbstractInplaceInput) component).getValue();
+ public String getValue(FacesContext facesContext, UIComponent component) throws
IOException {
+ AbstractInplaceInput inplaceInput = (AbstractInplaceInput)component;
+ String value = getInputValue(facesContext, inplaceInput);
+ if(value == null || "".equals(value)) {
+ value = inplaceInput.getDefaultLabel();
+ }
return value;
}
-
+
public String getResourcePath(FacesContext context, String resourceName) {
if (resourceName != null) {
ResourceHandler resourceHandler =
context.getApplication().getResourceHandler();
@@ -188,12 +181,13 @@
options.put(OPTIONS_INPUT, clientId + ":input");
options.put(OPTIONS_LABEL, clientId + ":label");
options.put(OPTIONS_FOCUS, clientId + ":focus");
+ options.put(OPTIONS_DEFAULT_LABEL, inplaceInput.getDefaultLabel());
boolean showControls = inplaceInput.isShowControls();
options.put(OPTIONS_SHOWCONTROLS, showControls);
if(showControls) {
- options.put(OPTIONS_BTN_OK, clientId + ":okbtn");
- options.put(OPTIONS_BTN_CANCEL, clientId + ":cancelbtn");
+ options.put(OPTIONS_BUTTON_OK, clientId + ":okbtn");
+ options.put(OPTIONS_BUTTON_CANCEL, clientId + ":cancelbtn");
}
function.addParameter(options);
Modified:
trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/inplaceInput.js
===================================================================
---
trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/inplaceInput.js 2010-08-31
12:14:40 UTC (rev 19036)
+++
trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/inplaceInput.js 2010-08-31
12:35:45 UTC (rev 19037)
@@ -28,21 +28,26 @@
$super.constructor.call(this, id);
this.attachToDom(id);
- this.namespace = this.namespace ||
"."+rf.Event.createNamespace(this.name, this.id);
+ this.namespace = this.namespace || "." +
rf.Event.createNamespace(this.name, this.id);
this.currentState = options.state;
this.editEvent = options.editEvent;
this.noneCss = options.noneCss;
this.changedCss = options.changedCss;
this.showControls = options.showControls;
+ this.defaultLabel = options.defaultLabel;
this.element = $(document.getElementById(id));
this.editContainer = $(document.getElementById(options.editContainer));
this.input = $(document.getElementById(options.input));
this.label = $(document.getElementById(options.label));
this.focusElement = $(document.getElementById(options.focusElement));
- this.initialValue = this.label.text();
+ var label = this.label.text();
+ var inputLabel = this.input.val();
+
+ this.initialValue = (label == inputLabel) ? label : "";
+
this.element.bind(this.editEvent, $.proxy(this.__editHandler, this));
this.input.bind("focus", $.proxy(this.__editHandler, this));
this.input.bind("change", $.proxy(this.__changeHandler, this));
@@ -66,7 +71,8 @@
$.extend(rf.ui.InplaceInput.prototype, ( function () {
var isSaved = false;
-
+ var isValueChanged = false;
+
return {
name : "inplaceInput",
@@ -86,6 +92,10 @@
var inputValue = this.input.val();
if(inputValue.length > 0) {
this.label.text(inputValue);
+ isValueChanged = true;
+ } else {
+ this.label.text(this.defaultLabel);
+ isValueChanged = false;
}
if(inputValue != this.initialValue) {
@@ -98,7 +108,10 @@
},
cancel: function() {
- var text = this.label.text();
+ var text = "";
+ if(isValueChanged) {
+ text = this.label.text();
+ }
this.input.val(text);
isSaved = true;
this.__hide();
Modified: trunk/ui/input/ui/src/main/templates/inplaceInput.template.xml
===================================================================
--- trunk/ui/input/ui/src/main/templates/inplaceInput.template.xml 2010-08-31 12:14:40 UTC
(rev 19036)
+++ trunk/ui/input/ui/src/main/templates/inplaceInput.template.xml 2010-08-31 12:35:45 UTC
(rev 19037)
@@ -26,7 +26,7 @@
<input id="#{clientId}:focus" type="image"
style="position: absolute; top: 0px; left: 0px; outline-style: none;"
class="rf-ii-none"/>
<span id="#{clientId}:edit" class="#{getEditStyleClass(component,
inplaceState)}">
<input id="#{clientId}:input" autocomplete="off"
name="#{clientId}:input"
- type="text" value="#{inplaceValue}" class="rf-ii-f"
style="width: #{component.attributes['inputWidth']};"
+ type="text" value="#{getInputValue(facesContext, component)}"
class="rf-ii-f" style="width:
#{component.attributes['inputWidth']};"
cdk:passThrough="tabIndex">
<cdk:call expression="renderInputHandlers(facesContext,
component);"/>
</input>