• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSF with Facelets - Setting maxlength attribute probelm

 
Punter Java
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have just started working on JSF along with facelets. I have created a xhtml file that contains a <h:inputText> widget. I want to set the maxlength and size attributes of the text field. Below are the options that i have tried:

option 1


option 2


When using option 1, the text box is rendered correctly but the maxlength attribute is ignored. I cant see that in the HTML.

When using option 2, I get the following error:


Can you please help me out in setting the maxlength attribute for <h:inputText>? I dont know what am I doing wrong. Have done a lot of google on this, but for no use.

Any help would be really appreciated.

Thanks
 
Punter Java
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just one more note: Same is the case with the size attribute. It is also getting ignored in option 1 and getting the same error in option 2
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18277
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"maxlength" is the Maximum number of characters that the input control will let you type in. JSF is generating an HTML '<INPUT TYPE="TEXT" SIZE="5" MAXLENGTH="4">'.

A "size" less than "maxlength" would be meaningless, except that all "size" does is provide a hint to the browser about the physical width of the input control - when not overridden by CSS.

Since all JSF does is propagate these attributes into the generated HTML, if you can make it work with straight HTML, it should work in JSF as well. You didn't supply a "value" attribute, though, and you need to.
 
Punter Java
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This works with HTML but unfortunately not with JSF. The size attribute has the value "5" and the maxlength has the value "4". So, size is indeed greater than maxlength, and it is not getting overridden by any CSS.

I have provided value to maxlength in f:attribute tag. Please let me know if there is anything more to it.

Thanks for the post!
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18277
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By the way....

We don't have many rules here at the JavaRanch, but we do insist that you use your Real Name and not some sort of "handle" or obvious alias. If you're not sure about this, see
http://www.javaranch.com/name.jsp .
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic