diff --git a/src/main/config/component/watermark.xml b/src/main/config/component/watermark.xml index e54a7da..12cf919 100755 --- a/src/main/config/component/watermark.xml +++ b/src/main/config/component/watermark.xml @@ -8,7 +8,12 @@ <classname>org.richfaces.component.html.HtmlWatermark</classname> <superclass>org.richfaces.component.UIWatermark</superclass> <description> - <![CDATA[]]> + <![CDATA[ + Adds watermark capability to HTML input and textarea elements. + A watermark typically appears as light gray text within an input or textarea element whenever + the element is empty and does not have focus. This provides a hint to the user as to what + the input or textarea element is used for, or the type of input that is required. + ]]> </description> <renderer generate="true" override="true"> <name>org.richfaces.component.renderkit.html.WatermarkRenderer</name> @@ -33,5 +38,30 @@ attribute. </description> </property> + <property> + <name>suffix</name> + <classname>java.lang.String</classname> + <description> + Use this if watermark should be attached to element with id different then component id. + i.e.: rich:comboBox with id="combo" nested in form with id="f" renders input with + clientId="f:combocomboboxField" + So in order to attach watermark to that element provide suffix="comboboxField". + </description> + </property> + <property> + <name>for</name> + <classname>java.lang.String</classname> + <description> + Use this if watermark cannot be nested within come components i.e. in calendar. + + Example 1: rich:calendar with id="c" nested in form with id="f" renders input with + clientId="f:cInputDate". + rich:calendar also gets messed up if watermark is nested within, so place it outside of calendar. + So in order to attach watermark to that element provide for="c" suffix="InputDate". + + Example 2: watermark should be attached to pure html input (not jsf component) with id="htmlInput". + To achieve this provide for="htmlInput". + </description> + </property> </component> </components> diff --git a/src/main/java/org/richfaces/component/UIWatermark.java b/src/main/java/org/richfaces/component/UIWatermark.java index 566e172..b103036 100755 --- a/src/main/java/org/richfaces/component/UIWatermark.java +++ b/src/main/java/org/richfaces/component/UIWatermark.java @@ -3,12 +3,23 @@ package org.richfaces.component; import javax.faces.component.UIOutput; public abstract class UIWatermark extends UIOutput { +// ------------------------------ FIELDS ------------------------------ - public static final String COMPONENT_TYPE = "org.richfaces.Watermark"; public static final String COMPONENT_FAMILY = "org.richfaces.Watermark"; + public static final String COMPONENT_TYPE = "org.richfaces.Watermark"; + +// -------------------------- OTHER METHODS -------------------------- + + public abstract String getFor(); + public abstract String getStyleClass(); + public abstract String getSuffix(); + + public abstract void setFor(String _for); + public abstract void setStyleClass(String styleClass); + public abstract void setSuffix(String suffix); } diff --git a/src/main/templates/htmlWatermark.jspx b/src/main/templates/htmlWatermark.jspx index 7b679a7..d704df6 100755 --- a/src/main/templates/htmlWatermark.jspx +++ b/src/main/templates/htmlWatermark.jspx @@ -19,7 +19,26 @@ <jsp:scriptlet> <![CDATA[ - String target = getUtils().clientId(context,component.getParent()); + String sid = (String) component.getAttributes().get("for"); + String target; + if (sid != null && ! "".equals(sid)) { + try { + UIComponent forcomp = getUtils().findComponentFor((UIComponent)component,sid); + if (forcomp != null) { + target = forcomp.getClientId(context); + } else { + target = sid; + } + }catch(IllegalArgumentException e) { + target = sid; + } + } else { + target = component.getParent().getClientId(context); + } + String suffix = component.getSuffix(); + if(suffix != null && !"".equals(suffix)) { + target += suffix; + } variables.setVariable("for",target); ]]> </jsp:scriptlet>