This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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:
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.
Joined: Oct 01, 2009
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
"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.
An IDE is no substitute for an Intelligent Developer.
Joined: Oct 01, 2009
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.
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