Commit e9836c4e879ce7f45d5e83cb1b2eade07ce1c587

Authored by bernard
1 parent 972d686a

Added "for" and "suffix" attributes to watermark component.

... ... @@ -8,7 +8,12 @@
8 8 <classname>org.richfaces.component.html.HtmlWatermark</classname>
9 9 <superclass>org.richfaces.component.UIWatermark</superclass>
10 10 <description>
11   - <![CDATA[]]>
  11 + <![CDATA[
  12 + Adds watermark capability to HTML input and textarea elements.
  13 + A watermark typically appears as light gray text within an input or textarea element whenever
  14 + the element is empty and does not have focus. This provides a hint to the user as to what
  15 + the input or textarea element is used for, or the type of input that is required.
  16 + ]]>
12 17 </description>
13 18 <renderer generate="true" override="true">
14 19 <name>org.richfaces.component.renderkit.html.WatermarkRenderer</name>
... ... @@ -33,5 +38,30 @@
33 38 attribute.
34 39 </description>
35 40 </property>
  41 + <property>
  42 + <name>suffix</name>
  43 + <classname>java.lang.String</classname>
  44 + <description>
  45 + Use this if watermark should be attached to element with id different then component id.
  46 + i.e.: rich:comboBox with id="combo" nested in form with id="f" renders input with
  47 + clientId="f:combocomboboxField"
  48 + So in order to attach watermark to that element provide suffix="comboboxField".
  49 + </description>
  50 + </property>
  51 + <property>
  52 + <name>for</name>
  53 + <classname>java.lang.String</classname>
  54 + <description>
  55 + Use this if watermark cannot be nested within come components i.e. in calendar.
  56 +
  57 + Example 1: rich:calendar with id="c" nested in form with id="f" renders input with
  58 + clientId="f:cInputDate".
  59 + rich:calendar also gets messed up if watermark is nested within, so place it outside of calendar.
  60 + So in order to attach watermark to that element provide for="c" suffix="InputDate".
  61 +
  62 + Example 2: watermark should be attached to pure html input (not jsf component) with id="htmlInput".
  63 + To achieve this provide for="htmlInput".
  64 + </description>
  65 + </property>
36 66 </component>
37 67 </components>
... ...
... ... @@ -3,12 +3,23 @@ package org.richfaces.component;
3 3 import javax.faces.component.UIOutput;
4 4
5 5 public abstract class UIWatermark extends UIOutput {
  6 +// ------------------------------ FIELDS ------------------------------
6 7
7   - public static final String COMPONENT_TYPE = "org.richfaces.Watermark";
8 8 public static final String COMPONENT_FAMILY = "org.richfaces.Watermark";
9 9
  10 + public static final String COMPONENT_TYPE = "org.richfaces.Watermark";
  11 +
  12 +// -------------------------- OTHER METHODS --------------------------
  13 +
  14 + public abstract String getFor();
  15 +
10 16 public abstract String getStyleClass();
11 17
  18 + public abstract String getSuffix();
  19 +
  20 + public abstract void setFor(String _for);
  21 +
12 22 public abstract void setStyleClass(String styleClass);
13 23
  24 + public abstract void setSuffix(String suffix);
14 25 }
... ...
... ... @@ -19,7 +19,26 @@
19 19
20 20 <jsp:scriptlet>
21 21 <![CDATA[
22   - String target = getUtils().clientId(context,component.getParent());
  22 + String sid = (String) component.getAttributes().get("for");
  23 + String target;
  24 + if (sid != null && ! "".equals(sid)) {
  25 + try {
  26 + UIComponent forcomp = getUtils().findComponentFor((UIComponent)component,sid);
  27 + if (forcomp != null) {
  28 + target = forcomp.getClientId(context);
  29 + } else {
  30 + target = sid;
  31 + }
  32 + }catch(IllegalArgumentException e) {
  33 + target = sid;
  34 + }
  35 + } else {
  36 + target = component.getParent().getClientId(context);
  37 + }
  38 + String suffix = component.getSuffix();
  39 + if(suffix != null && !"".equals(suffix)) {
  40 + target += suffix;
  41 + }
23 42 variables.setVariable("for",target);
24 43 ]]>
25 44 </jsp:scriptlet>
... ...
Please register or login to post a comment