最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

java - JSF : How put onfocus, onblur effect in input field? - Stack Overflow

programmeradmin6浏览0评论

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
Add a ment  | 

3 Answers 3

Reset to default 3

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

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.

发布评论

评论列表(0)

  1. 暂无评论