File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSF and the fly likes JSF with Facelets - Setting maxlength attribute probelm Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "JSF with Facelets - Setting maxlength attribute probelm" Watch "JSF with Facelets - Setting maxlength attribute probelm" New topic
Author

JSF with Facelets - Setting maxlength attribute probelm

Punter Java
Greenhorn

Joined: Oct 01, 2009
Posts: 3
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

Joined: Oct 01, 2009
Posts: 3
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

Joined: Jun 25, 2001
Posts: 16054
    
  21

"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.


Customer surveys are for companies who didn't pay proper attention to begin with.
Punter Java
Greenhorn

Joined: Oct 01, 2009
Posts: 3
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

Joined: Jun 25, 2001
Posts: 16054
    
  21

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 .
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSF with Facelets - Setting maxlength attribute probelm