Author: abelevich
Date: 2010-09-07 11:04:17 -0400 (Tue, 07 Sep 2010)
New Revision: 19128
Modified:
branches/RF-8992/ui/input/ui/src/main/java/org/richfaces/component/AbstractInplaceSelect.java
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/inplaceInput.js
branches/RF-8992/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/inplaceSelect.ecss
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 script encoding for th inplaeInput, fix InplaceIput script building
Modified:
branches/RF-8992/ui/input/ui/src/main/java/org/richfaces/component/AbstractInplaceSelect.java
===================================================================
---
branches/RF-8992/ui/input/ui/src/main/java/org/richfaces/component/AbstractInplaceSelect.java 2010-09-07
15:02:31 UTC (rev 19127)
+++
branches/RF-8992/ui/input/ui/src/main/java/org/richfaces/component/AbstractInplaceSelect.java 2010-09-07
15:04:17 UTC (rev 19128)
@@ -26,10 +26,21 @@
public static final String COMPONENT_FAMILY =
"org.richfaces.InplaceSelect";
+ @Attribute(defaultValue="250px")
+ public abstract String getListWidth();
+
+ @Attribute(defaultValue="100px")
+ public abstract String getListHeight();
+
@Attribute(defaultValue="InplaceState.ready")
public abstract InplaceState getState();
@Attribute
public abstract String getDefaultLabel();
-
+
+ @Attribute(defaultValue="false")
+ public abstract boolean isShowControls();
+
+ @Attribute(defaultValue="click")
+ public abstract String getEditEvent();
}
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-07
15:02:31 UTC (rev 19127)
+++
branches/RF-8992/ui/input/ui/src/main/java/org/richfaces/renderkit/InplaceInputBaseRenderer.java 2010-09-07
15:04:17 UTC (rev 19128)
@@ -36,7 +36,6 @@
import org.ajax4jsf.javascript.JSFunction;
import org.ajax4jsf.renderkit.RendererUtils.HTML;
-import org.richfaces.component.AbstractInplaceInput;
import org.richfaces.component.InplaceComponent;
import org.richfaces.component.InplaceState;
import org.richfaces.component.util.HtmlUtil;
@@ -161,32 +160,49 @@
}
public void buildScript(ResponseWriter writer, FacesContext facesContext, UIComponent
component) throws IOException {
- AbstractInplaceInput inplaceInput = (AbstractInplaceInput)component;
- JSFunction function = new JSFunction("new RichFaces.ui.InplaceInput");
-
- String clientId = inplaceInput.getClientId(facesContext);
+ if(!(component instanceof InplaceComponent)) {
+ return;
+ }
+
+ String scriptName = getScriptName();
+ JSFunction function = new JSFunction(scriptName);
+ String clientId = component.getClientId(facesContext);
+ Map<String, Object> options = createInplaceComponentOptions(clientId,
(InplaceComponent)component);
+ addToOptions(component, options);
+ function.addParameter(clientId);
+ function.addParameter(options);
+ writer.write(function.toString());
+ }
+
+ protected String getScriptName() {
+ return "new RichFaces.ui.InplaceInput";
+ }
+
+ private Map<String, Object> createInplaceComponentOptions(String clientId,
InplaceComponent inplaceComponent) {
Map<String, Object> options = new HashMap<String, Object>();
- options.put(OPTIONS_EDIT_EVENT, inplaceInput.getEditEvent());
+ options.put(OPTIONS_EDIT_EVENT, inplaceComponent.getEditEvent());
options.put(OPTIONS_NONE_CSS, getNoneCss());
options.put(OPTIONS_CHANGED_CSS, getChangedStateCss());
options.put(OPTIONS_EDIT_CONTAINER, clientId + ":edit");
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());
+ options.put(OPTIONS_DEFAULT_LABEL, inplaceComponent.getDefaultLabel());
+
+ boolean showControls = inplaceComponent.isShowControls();
- boolean showControls = inplaceInput.isShowControls();
options.put(OPTIONS_SHOWCONTROLS, showControls);
if(showControls) {
options.put(OPTIONS_BUTTON_OK, clientId + ":okbtn");
options.put(OPTIONS_BUTTON_CANCEL, clientId + ":cancelbtn");
- }
-
- function.addParameter(clientId);
- function.addParameter(options);
- writer.write(function.toString());
+ }
+ return options;
}
+ public void addToOptions(UIComponent component, Map<String, Object> parameters)
{
+ //override this method if you need additional options
+ }
+
public String getReadyStateCss() {
return "rf-ii-d-s";
}
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-07
15:02:31 UTC (rev 19127)
+++
branches/RF-8992/ui/input/ui/src/main/java/org/richfaces/renderkit/InplaceSelectBaseRenderer.java 2010-09-07
15:04:17 UTC (rev 19128)
@@ -1,16 +1,21 @@
package org.richfaces.renderkit;
import java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
+import java.util.ArrayList;
+import java.util.List;
import javax.faces.application.ResourceDependencies;
import javax.faces.application.ResourceDependency;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
+import javax.faces.model.SelectItem;
-import org.ajax4jsf.javascript.JSFunction;
+import org.ajax4jsf.javascript.ScriptString;
+import org.ajax4jsf.javascript.ScriptUtils;
+import org.ajax4jsf.renderkit.RendererUtils.HTML;
+import org.ajax4jsf.util.InputUtils;
+import org.ajax4jsf.util.SelectUtils;
import org.richfaces.component.AbstractInplaceSelect;
@@ -23,23 +28,77 @@
@ResourceDependency(name = "jquery.js"), @ResourceDependency(name =
"richfaces.js"),
@ResourceDependency(name = "richfaces-event.js"),
@ResourceDependency(name = "richfaces-base-component.js"),
+ @ResourceDependency(library="org.richfaces", name =
"inplaceInput.js"),
@ResourceDependency(library="org.richfaces", name =
"inplaceSelect.js"),
@ResourceDependency(library="org.richfaces", name =
"inplaceSelect.ecss") })
public class InplaceSelectBaseRenderer extends InplaceInputBaseRenderer {
+
+ protected static final class ClientSelectItem implements ScriptString {
+ private String label;
+ private String convertedValue;
+ public ClientSelectItem(String convertedValue, String label) {
+ super();
+ this.convertedValue = convertedValue;
+ this.label = label;
+ }
+
+ public String getLabel() {
+ return label;
+ }
+
+ public String getConvertedValue() {
+ return convertedValue;
+ }
+
+ public void appendScript(StringBuffer functionString) {
+ functionString.append(this.toScript());
+ }
+
+ public String toScript() {
+ return "[" + ScriptUtils.toScript(label) + ", " +
ScriptUtils.toScript(convertedValue) + "]";
+ }
+ }
+
@Override
- public void buildScript(ResponseWriter writer, FacesContext facesContext, UIComponent
component) throws IOException {
+ protected String getScriptName() {
+ return "new RichFaces.ui.InplaceSelect";
+ }
+
+ public List<ClientSelectItem> getConvertedSelectItems(FacesContext
facesContext, UIComponent component) {
AbstractInplaceSelect inplaceSelect = (AbstractInplaceSelect)component;
- JSFunction function = new JSFunction("new
RichFaces.ui.InplaceSelect");
-
- String clientId = inplaceSelect.getClientId(facesContext);
- Map<String, Object> options = new HashMap<String, Object>();
-
- function.addParameter(clientId);
- function.addParameter(options);
- writer.write(function.toString());
+ List<SelectItem> selectItems = SelectUtils.getSelectItems(facesContext,
inplaceSelect);
+ List<ClientSelectItem> clientSelectItems = new
ArrayList<InplaceSelectBaseRenderer.ClientSelectItem>();
+ for (SelectItem selectItem: selectItems) {
+ String convertedStringValue =
InputUtils.getConvertedStringValue(facesContext, inplaceSelect, selectItem.getValue());
+ String label = selectItem.getLabel();
+ clientSelectItems.add(new ClientSelectItem(convertedStringValue, label));
+ }
+ return clientSelectItems;
}
+ 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();
+ for(ClientSelectItem clientSelectItem: clientSelectItems) {
+ writer.startElement(HTML.SPAN_ELEM, inplaceSelect);
+ writer.writeAttribute(HTML.CLASS_ATTRIBUTE, getOptionCss() , null);
+
+ String label = clientSelectItem.getLabel();
+
+ if(label != null && label.trim().length() > 0) {
+ writer.writeText(label, null);
+ } else {
+ writer.write("\u00a0");
+ }
+ writer.endElement(HTML.SPAN_ELEM);
+ writer.startElement("br", inplaceSelect);
+ writer.endElement("br");
+ }
+ }
+ }
+
public String getListStyles(FacesContext facesContext, UIComponent component) {
return "";
}
@@ -59,4 +118,9 @@
public String getNoneCss() {
return "rf-is-none";
}
+
+ public String getOptionCss() {
+ return "insel_option insel_font";
+ }
+
}
Modified:
branches/RF-8992/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/inplaceInput.js
===================================================================
---
branches/RF-8992/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/inplaceInput.js 2010-09-07
15:02:31 UTC (rev 19127)
+++
branches/RF-8992/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/inplaceInput.js 2010-09-07
15:04:17 UTC (rev 19128)
@@ -28,7 +28,7 @@
$super.constructor.call(this, id);
this.attachToDom(id);
- this.namespace = this.namespace || "." +
rf.Event.createNamespace(this.name, this.id);
+ this.namespace = this.getNamespace() || "." +
rf.Event.createNamespace(this.getName(), this.id);
this.currentState = options.state;
this.editEvent = options.editEvent;
@@ -63,7 +63,7 @@
};
// Extend component class and add protected methods from parent class to our
container
- rf.BaseComponent.extend( rf.ui.InplaceInput);
+ rf.BaseComponent.extend(rf.ui.InplaceInput);
// define super class link
var $super = rf.ui.InplaceInput.$super;
@@ -78,6 +78,10 @@
/****************** public methods *****************************************/
+ getName: function() {
+ return this.name;
+ },
+
getNamespace: function () {
return this.namespace;
},
Modified:
branches/RF-8992/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/inplaceSelect.ecss
===================================================================
---
branches/RF-8992/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/inplaceSelect.ecss 2010-09-07
15:02:31 UTC (rev 19127)
+++
branches/RF-8992/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/inplaceSelect.ecss 2010-09-07
15:04:17 UTC (rev 19128)
@@ -22,7 +22,7 @@
display : inline-block;
position : relative;
white-space : nowrap;
- background-color : '#{richSkin.editBackgroundColor}';
+ background-color : '#{richSkin.editorBackgroundColor}';
border-bottom-width : 1px;
border-bottom-style : dashed;
border-bottom-color : '#{richSkin.generalTextColor}';
@@ -41,7 +41,6 @@
top : 0px;
left : 0px;
width : 100px;
- display : inline-block;
}
.insel_field {
@@ -111,7 +110,6 @@
.insel_list_scroll {
overflow : auto;
overflow-x : hidden;
- height : 100px;
display: inline-block;
width: 100%;
}
@@ -134,10 +132,6 @@
border-color : '#{richSkin.generalTextColor}';
}
-.insel_width_list {
- width : 250px;
-}
-
.insel_select {
padding : 1px;
width : 100%;
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-07
15:02:31 UTC (rev 19127)
+++
branches/RF-8992/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/inplaceSelect.js 2010-09-07
15:04:17 UTC (rev 19128)
@@ -2,8 +2,19 @@
rf.ui = rf.ui || {};
- rf.ui.InplaceSelect = function(id, options) {
-
- }
+ rf.ui.InplaceSelect = function(id, options) {
+ $super.constructor.call(this, id, options);
+ }
+
+ rf.ui.InplaceInput.extend(rf.ui.InplaceSelect);
+ var $super = rf.ui.InplaceSelect.$super;
+
+ $.extend(rf.ui.InplaceSelect.prototype, function () {
+
+ return{
+ name : "inplaceSelect"
+ }
+ })
+
})(jQuery, window.RichFaces);
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-07
15:02:31 UTC (rev 19127)
+++ branches/RF-8992/ui/input/ui/src/main/templates/inplaceInput.template.xml 2010-09-07
15:04:17 UTC (rev 19128)
@@ -49,8 +49,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}"
- type="text" value="#{getInputValue(facesContext, component)}"
class="rf-ii-f" style="width:
#{component.attributes['inputWidth']};"
- cdk:passThrough="tabIndex">
+ 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>
<c:if test="#{component.attributes['showControls']}">
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-07
15:02:31 UTC (rev 19127)
+++ branches/RF-8992/ui/input/ui/src/main/templates/inplaceSelect.template.xml 2010-09-07
15:04:17 UTC (rev 19128)
@@ -34,6 +34,9 @@
<cdk:object type="java.lang.String" name="inplaceValue"
value="#{getValue(facesContext, component)}" />
+ <cdk:object type="java.util.List"
type-arguments="InplaceSelectBaseRenderer.ClientSelectItem"
name="clientSelectItems"
+ value="#{getConvertedSelectItems(facesContext, component)}" />
+
<span id="#{clientId}" class="#{getReadyStyleClass(component,
inplaceState)}"
cdk:passThroughWithExclusions="id class">
@@ -43,19 +46,17 @@
<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)}"
- style="display: inline-block;">
+ <span id="#{clientId}:edit" class="#{getEditStyleClass(component,
inplaceState)}">
<input id="#{clientId}:input" autocomplete="off"
name="#{clientId}"
type="text" value="#{getInputValue(facesContext, component)}"
- class="insel_field" style="width:
#{component.attributes['inputWidth']};"
- cdk:passThrough="tabIndex" readonly="readonly">
+ class="insel_field" style="width:
#{component.attributes['inputWidth']};" readonly="readonly"
+ cdk:passThrough="tabIndex">
<cdk:call expression="renderInputHandlers(facesContext, component);"
/>
</input>
<c:if test="#{component.attributes['showControls']}">
<span class="insel_btn_preposition">
<span class="insel_btn_position">
<span id="#{clientId}:btnshadow" class="insel_shadow">
-
<span class="insel_shadow_t"></span>
<span class="insel_shadow_l"></span>
<span class="insel_shadow_r"></span>
@@ -72,29 +73,21 @@
onmouseout="this.className='insel_btn_press'"
onmouseup="this.className='insel_btn'" />
<br />
</span>
-
</span>
</span>
</span>
</c:if>
<br/>
<span class="insel_list_cord">
- <span class="insel_list_position insel_width_list">
+ <span class="insel_list_position" style="width:
#{component.attributes['listWidth']}">
<span class="insel_shadow">
<span class="insel_shadow_t"></span>
<span class="insel_shadow_l"></span>
<span class="insel_shadow_r"></span>
<span class="insel_shadow_b"></span>
<span class="insel_list_decoration">
- <span class="insel_list_scroll">
- <span class="insel_option insel_font">Option 1</span>
- <br/>
- <span class="insel_option insel_font">Option 2</span>
- <br/>
- <span class="insel_option insel_font">Option 3</span>
- <br/>
- <span class="insel_option insel_font">Option 4</span>
- <br/>
+ <span class="insel_list_scroll" style="height:
#{component.attributes['listHeight']}">
+ <cdk:call expression="encodeOptions(facesContext, component,
clientSelectItems);"/>
</span>
</span>
</span>