Reputation: 1507
I am using JSF 2.0 with Primefaces 3.2. I have a text area with a maxlength set to 4000. But the text area allows me to type 4001 chars. (Always one extra character). I have been setting my maxlength to 3999 to avoid this problem Is this a known issue? I dont see this problem on showcase, any ideas?
<p:inputTextarea id="text" value="#{controller.text}" maxlength="4000"
rows="6" cols="150" autoResize="true" required="true" requiredMessage="Text is required" rendered="#{controller.condition}"/>
Upvotes: 2
Views: 4055
Reputation: 2485
Sometimes enter counts as 2 characters: \r\n instead of just \n. In such cases try to replace all of these characters to \n in your setter method. You can do that for example by using StringUtils.replace() method:
your_string = StringUtils.replace(your_string, "\r\n", "\n");
Upvotes: 6
Reputation: 873
Using UTF-8 characters that take up more than one byte to store still counts as one character, but you can run into trouble with this in your database (getting an error message that it's more than 4000 characters).
You say it's always +1 character, check out using only ASCII characters (numbers+english letters).
ps: (if you are using nobleCount to display the remaing characters, it also has some issues with UTF-8 characters/some special characters).
Upvotes: 2