I'm thinking about how can I implement onfocus
and onblur
effects in my input field in JSF 2.0.
I do the following in HTML:
<input type="text" name="name" id="name" size="30" value="Name (required)"
onblur="if (this.value == ''){this.value = 'Name (required)'; }"
onfocus="if (this.value == 'Name (required)') {this.value = ''; }"
class="text-input" />
Now I'm wondering how I could do this in JSF 2.0. Does anyone have an idea?
EDIT
I'm trying the attribute 'onblur' and 'onfocus' but still nothing appearing in my input field.
<h:inputText onblur="Nome" onfocus="" ></h:inputText>
I'm thinking about how can I implement onfocus
and onblur
effects in my input field in JSF 2.0.
I do the following in HTML:
<input type="text" name="name" id="name" size="30" value="Name (required)"
onblur="if (this.value == ''){this.value = 'Name (required)'; }"
onfocus="if (this.value == 'Name (required)') {this.value = ''; }"
class="text-input" />
Now I'm wondering how I could do this in JSF 2.0. Does anyone have an idea?
EDIT
I'm trying the attribute 'onblur' and 'onfocus' but still nothing appearing in my input field.
<h:inputText onblur="Nome" onfocus="" ></h:inputText>
Share
Improve this question
edited Jul 21, 2011 at 9:22
Jasper
2,1764 gold badges31 silver badges51 bronze badges
asked Jul 20, 2011 at 19:07
Valter SilvaValter Silva
16.7k53 gold badges141 silver badges221 bronze badges
1
- The same attributes are supported in most JSF ponents. Just use them and try. – adarshr Commented Jul 20, 2011 at 19:10
3 Answers
Reset to default 3You can just use the same attributes as your HTML sample. The following piece of code works just fine:
<h:inputText id="name" value="Name (required)"
onblur="if (this.value == ''){this.value = 'Name (required)'; }"
onfocus="if (this.value == 'Name (required)') {this.value = ''; }" />
Simply use onblur
attribute of <h:inputtext>
If you do a view source on the rendered html page, does it show the html that you are looking for? - If so you are good to go or atleast it is working as designed :-). Basically whatever jsf h: type tags that you have should be rendered as equivalent html.