Author: abelevich
Date: 2008-04-11 05:45:08 -0400 (Fri, 11 Apr 2008)
New Revision: 7752
Modified:
trunk/ui/inplaceInput/src/main/java/org/richfaces/component/UIInplaceInput.java
trunk/ui/inplaceInput/src/main/java/org/richfaces/renderkit/InplaceInputBaseRenderer.java
Log:
applying review
Modified: trunk/ui/inplaceInput/src/main/java/org/richfaces/component/UIInplaceInput.java
===================================================================
---
trunk/ui/inplaceInput/src/main/java/org/richfaces/component/UIInplaceInput.java 2008-04-11
09:44:49 UTC (rev 7751)
+++
trunk/ui/inplaceInput/src/main/java/org/richfaces/component/UIInplaceInput.java 2008-04-11
09:45:08 UTC (rev 7752)
@@ -18,12 +18,9 @@
* <p>The standard component type for this component.</p>
*/
public static final String COMPONENT_TYPE = "org.richfaces.InplaceInput";
+ final static public String COMPONENT_FAMILY =
"org.richfaces.InplaceInput";
public static final String VALUE_SUFFIX = "value";
-
- public abstract String getDefaultLabel();
- public abstract void setDefaultLabel(String label);
-
-
-
+ public abstract String getDefaultLabel();
+ public abstract void setDefaultLabel(String label);
}
\ No newline at end of file
Modified:
trunk/ui/inplaceInput/src/main/java/org/richfaces/renderkit/InplaceInputBaseRenderer.java
===================================================================
---
trunk/ui/inplaceInput/src/main/java/org/richfaces/renderkit/InplaceInputBaseRenderer.java 2008-04-11
09:44:49 UTC (rev 7751)
+++
trunk/ui/inplaceInput/src/main/java/org/richfaces/renderkit/InplaceInputBaseRenderer.java 2008-04-11
09:45:08 UTC (rev 7752)
@@ -8,7 +8,9 @@
import javax.faces.convert.ConverterException;
import org.ajax4jsf.javascript.JSFunctionDefinition;
+import org.ajax4jsf.javascript.ScriptUtils;
import org.ajax4jsf.renderkit.HeaderResourcesRendererBase;
+import org.ajax4jsf.renderkit.RendererUtils;
import org.ajax4jsf.util.InputUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -25,13 +27,7 @@
private static Log logger = LogFactory.getLog(InplaceInputBaseRenderer.class);
private static final String CONTROLS_FACET = "controls";
-
- private static final int NORMAL_KEY = 0;
-
- private static final int HOVERED_KEY = 1;
-
- private static final int EDITABLE_KEY = 2;
-
+
private static final String INPLACE_COMPONENT = "COMPONENT";
private static final String INPLACE_CHANGED = "CHANGED";
@@ -55,10 +51,49 @@
private static final String INPLACE_CSS_HOVER = "hover";
private static final String EMPTY_DEFAULT_LABEL =
"   ";
+
+ private static enum States {
+ NORMAL {String createCss(UIComponent component, String suffix){
+ StringBuilder builder = new StringBuilder();
+ builder.append(INPLACE_CSS_PUBLIC);
+ builder.append(" ");
+ builder.append(INPLACE_CSS_PUBLIC + "-" + suffix);
+ Object value = component.getAttributes().get(suffix + "Class");
+ if (value != null) {
+ builder.append(" ");
+ builder.append(value);
+ }
+ return builder.toString();
+ };},
+ HOVERED {String createCss(UIComponent component , String suffix){
+ StringBuilder builder = new StringBuilder();
+ builder.append(INPLACE_CSS_PUBLIC + "-" + "input-" + suffix +
"-" + INPLACE_CSS_HOVER);
+ Object value = component.getAttributes().get(suffix + "HoverClass");
+ if (value != null) {
+ builder.append(" ");
+ builder.append(value);
+ }
+ return builder.toString();
+ }},
+ EDIT {String createCss(UIComponent component, String suffix){
+ StringBuilder builder = new StringBuilder();
+ builder.append(INPLACE_CSS_PUBLIC);
+ builder.append(" ");
+ builder.append(INPLACE_CSS_PUBLIC + "-" + suffix);
+ Object value = component.getAttributes().get(suffix + "Class");
+ if (value != null) {
+ builder.append(" ");
+ builder.append(value);
+ }
+ return builder.toString();
+ }};
+ abstract String createCss(UIComponent component, String suffix);
+ };
+
protected Class<UIInplaceInput> getComponentClass() {
- return UIInplaceInput.class;
+ return UIInplaceInput.class;
}
protected void doDecode(FacesContext context, UIComponent component) {
@@ -68,7 +103,6 @@
inplaceInput = (UIInplaceInput) component;
} else {
if (logger.isDebugEnabled()) {
-
logger.debug("No decoding necessary since the component "
+ component.getId() +
" is not an instance or a sub class of UIInplaceInput");
@@ -76,34 +110,28 @@
return;
}
- //TODO:
- //First check NULL clientId
-
+ String clientId = component.getClientId(context);
+ if (clientId == null) {
+ throw new NullPointerException("component client id is NULL" );
+ }
+
if (InputUtils.isDisabled(inplaceInput) || InputUtils.isReadOnly(inplaceInput)) {
if (logger.isDebugEnabled()) {
logger.debug(("No decoding necessary since the component "
+ component.getId() + " is disabled"));
}
- //TODO: return?
+ return;
}
- String clientId = component.getClientId(context);
- //TODO: NULL is NULL?
- if (clientId == null) {
- throw new NullPointerException("component " +
inplaceInput.getClientId(context) + " client id is NULL" );
- }
//TODO:
//Should use clientId instead?
clientId = clientId + UIInplaceInput.VALUE_SUFFIX;
- Map request = context.getExternalContext().getRequestParameterMap();
- //TODO:
- //Request.get is enough
- if (request.containsKey(clientId)) {
- String newValue = (String)request.get(clientId);
- if (newValue != null) {
+ Map <String, String> request =
context.getExternalContext().getRequestParameterMap();
+
+ String newValue = (String)request.get(clientId);
+ if (newValue != null) {
inplaceInput.setSubmittedValue(newValue);
- }
- }
+ }
}
//TODO:
@@ -124,16 +152,14 @@
}
public String encodeScriptAttributes(FacesContext context, UIComponent component) {
- //TODO:
- //Use string builder instead
- StringBuffer attributes = new StringBuffer();
+ StringBuilder attributes = new StringBuilder();
attributes.append("var attributes = ");
ScriptOptions options = new ScriptOptions(component);
String defaultLabel =
(String)component.getAttributes().get("defaultLabel");
- //TODO: length()==0
- if (defaultLabel == null || defaultLabel.equals("")) {
+
+ if (defaultLabel == null || defaultLabel.length() == 0) {
defaultLabel = EMPTY_DEFAULT_LABEL;
}
@@ -152,7 +178,7 @@
}
public String encodeScriptEvents(FacesContext context, UIComponent component) {
- StringBuffer events = new StringBuffer();
+ StringBuilder events = new StringBuilder();
events.append("var events = ");
ScriptOptions options = new ScriptOptions(component);
@@ -166,7 +192,7 @@
}
public String encodeInplaceInputCss(FacesContext context, UIComponent component) {
- StringBuffer cssMap = new StringBuffer();
+ StringBuilder cssMap = new StringBuilder();
cssMap.append("var classes = ");
ScriptOptions mainMap = new ScriptOptions(component);
@@ -174,79 +200,30 @@
ScriptOptions changedClasses = new ScriptOptions(component);
ScriptOptions viewClasses = new ScriptOptions(component);
- changedClasses.addOption(INPLACE_NORMAL, buildCss(component, NORMAL_KEY,
INPLACE_CSS_CHANGE) );
- changedClasses.addOption(INPLACE_HOVERED, buildCss(component, HOVERED_KEY,
INPLACE_CSS_CHANGE));
+ changedClasses.addOption(INPLACE_NORMAL, createCss(component, States.NORMAL,
INPLACE_CSS_CHANGE) );
+ changedClasses.addOption(INPLACE_HOVERED, createCss(component,States.HOVERED,
INPLACE_CSS_CHANGE));
- viewClasses.addOption(INPLACE_NORMAL, buildCss(component, NORMAL_KEY,
INPLACE_CSS_VIEW) );;
- viewClasses.addOption(INPLACE_HOVERED, buildCss(component, HOVERED_KEY,
INPLACE_CSS_VIEW));
+ viewClasses.addOption(INPLACE_NORMAL, createCss(component, States.NORMAL,
INPLACE_CSS_VIEW) );;
+ viewClasses.addOption(INPLACE_HOVERED, createCss(component,States.HOVERED,
INPLACE_CSS_VIEW));
componentClasses.addOption(INPLACE_CHANGED,changedClasses);
componentClasses.addOption(INPLACE_VIEW, viewClasses);
- componentClasses.addOption(INPLACE_EDITABLE,buildCss(component, EDITABLE_KEY,
INPLACE_CSS_EDITABLE));
+ componentClasses.addOption(INPLACE_EDITABLE,createCss(component, States.EDIT,
INPLACE_CSS_EDITABLE));
mainMap.addOption(INPLACE_COMPONENT, componentClasses);
cssMap.append(mainMap.toString());
return cssMap.toString();
}
- //TODO: use enum?
- private String buildCss(UIComponent component, int key, String suffix) {
- Object value;
- StringBuffer stringBuffer = new StringBuffer();
-
- switch (key) {
- case NORMAL_KEY:
- stringBuffer.append(INPLACE_CSS_PUBLIC);
- stringBuffer.append(" ");
- stringBuffer.append(INPLACE_CSS_PUBLIC + "-" + suffix);
- value = component.getAttributes().get(suffix + "Class");
- if (value != null) {
- stringBuffer.append(" ");
- stringBuffer.append(value);
- }
- break;
- case HOVERED_KEY:
- stringBuffer.append(INPLACE_CSS_PUBLIC + "-" + "input-" + suffix
+ "-" + INPLACE_CSS_HOVER);
- value = component.getAttributes().get(suffix + "HoverClass");
- if (value != null) {
- stringBuffer.append(" ");
- stringBuffer.append(value);
- }
- break;
-
- case EDITABLE_KEY:
- stringBuffer.append(INPLACE_CSS_PUBLIC);
- stringBuffer.append(" ");
- stringBuffer.append(INPLACE_CSS_PUBLIC + "-" + suffix);
- value = component.getAttributes().get(suffix + "Class");
- if (value != null) {
- stringBuffer.append(" ");
- stringBuffer.append(value);
- }
- break;
- }
- return stringBuffer.toString();
+ private String createCss(UIComponent component, States state, String suffix) {
+ return state.createCss(component, suffix);
}
- //TODO: remove?
public String getAsEventHandler(FacesContext context, UIComponent component, String
attributeName) {
- String event = (String) component.getAttributes().get(attributeName);
- String result = null;
-
- if (event != null) {
- event = event.trim();
-
- if (event.length() != 0) {
- JSFunctionDefinition function = new JSFunctionDefinition();
- function.addParameter("event");
- function.addToBody(event);
-
- result = function.toScript();
- }
- }
- return result;
+ JSFunctionDefinition script = RendererUtils.getAsEventHandler(context, component,
attributeName, null);
+ return ScriptUtils.toScript(script);
}
-
+
@Override
public Object getConvertedValue(FacesContext context, UIComponent component, Object
submittedValue) throws ConverterException {
return InputUtils.getConvertedValue(context, component, submittedValue);
@@ -257,8 +234,7 @@
}
protected boolean isEmptyDefaultLabel(String defaultLabel) {
- //TODO: remove != null?
- if (defaultLabel != null && EMPTY_DEFAULT_LABEL.equals(defaultLabel)) {
+ if (EMPTY_DEFAULT_LABEL.equals(defaultLabel)) {
return true;
}
return false;