Author: nbelaevski
Date: 2009-04-13 19:18:14 -0400 (Mon, 13 Apr 2009)
New Revision: 13553
Modified:
trunk/ui/colorPicker/src/main/java/org/richfaces/renderkit/ColorPickerRendererBase.java
trunk/ui/colorPicker/src/main/templates/org/richfaces/htmlColorPicker.jspx
Log:
https://jira.jboss.org/jira/browse/RF-6756
Modified:
trunk/ui/colorPicker/src/main/java/org/richfaces/renderkit/ColorPickerRendererBase.java
===================================================================
---
trunk/ui/colorPicker/src/main/java/org/richfaces/renderkit/ColorPickerRendererBase.java 2009-04-13
22:30:30 UTC (rev 13552)
+++
trunk/ui/colorPicker/src/main/java/org/richfaces/renderkit/ColorPickerRendererBase.java 2009-04-13
23:18:14 UTC (rev 13553)
@@ -1,6 +1,7 @@
package org.richfaces.renderkit;
import java.util.Set;
+import java.util.regex.Pattern;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
@@ -9,6 +10,7 @@
import org.ajax4jsf.javascript.JSFunctionDefinition;
import org.ajax4jsf.javascript.ScriptUtils;
import org.richfaces.component.UIColorPicker;
+import org.richfaces.component.util.MessageUtil;
public abstract class ColorPickerRendererBase extends InputRendererBase {
@@ -43,4 +45,20 @@
}
return builder.toString();
}
+
+ private static final Pattern[] COLOR_PATTERNS = {
+ Pattern.compile("(?:rgb|hsb)(?:\\D+\\d+){3}"),
+ Pattern.compile("^#[0-9A-Fa-f]{6}")
+ };
+
+ public void validateColorString(FacesContext context, UIComponent component, String
value) {
+ for (Pattern colorPattern : COLOR_PATTERNS) {
+ if (colorPattern.matcher(value).find()) {
+ return ;
+ }
+ }
+
+ throw new IllegalArgumentException("Illegal color value: [" + value + "]
for component " +
+ MessageUtil.getLabel(context, component));
+ }
}
\ No newline at end of file
Modified: trunk/ui/colorPicker/src/main/templates/org/richfaces/htmlColorPicker.jspx
===================================================================
--- trunk/ui/colorPicker/src/main/templates/org/richfaces/htmlColorPicker.jspx 2009-04-13
22:30:30 UTC (rev 13552)
+++ trunk/ui/colorPicker/src/main/templates/org/richfaces/htmlColorPicker.jspx 2009-04-13
23:18:14 UTC (rev 13553)
@@ -106,9 +106,17 @@
Boolean flat = (Boolean) component.getAttributes().get("flat");
colorMode = (String) component.getAttributes().get("colorMode");
showEvent = (String) component.getAttributes().get("showEvent");
+
+ boolean isRgbMode = "rgb".equals(colorMode);
if (value == null || value.length() == 0){
- value = "#ffffff";
+ if (isRgbMode) {
+ value = "rgb(255, 255, 255)";
+ } else {
+ value = "#ffffff";
+ }
+ } else {
+ validateColorString(context, component, value);
}
if(showEvent.startsWith("on")){