Valter Silva
Valter Silva

Reputation: 16656

JSF : How put onfocus, onblur effect in input field?

I'm thinking about how can I implement onfocus and onblur effects in my input field in JSF 2.0.

Example in HTML

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>

Upvotes: 1

Views: 15622

Answers (3)

Jasper
Jasper

Reputation: 2176

You 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 = ''; }" />

Upvotes: 3

OpenSource
OpenSource

Reputation: 2257

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.

Upvotes: 0

Jigar Joshi
Jigar Joshi

Reputation: 240898

Simply use onblur attribute of <h:inputtext>

Upvotes: 1

Related Questions