I have a primefaces textarea. User simply enters multiple lines in it and submits the form. In my backing bean, value is split at line-breaks. Each line is validated. The valid lines are removed from the string and invalid lines are kept, and again sent to the user.
Split code:
StringTokenizer tokens=new StringTokenizer(value,"\n\r");
Re-fill value with invalid lines:
valueStrBldr.append(invalidLine).append("\n\r");
The problem is that when value is reloaded to text area it has a lot of unwanted line breaks and empty lines. Does it have to do something with platform dependent line breaks?
When I remove \r , the problem is solved, but then the value is not split correctly — I mean why inconsistency?
I suggest to use
BufferedReader#readLine()instead to read lines on linebreaks. This covers all possible platform specific linebreaks such as\r\n,\rand\nwithout that you need to worry about (please note that\n\ris not a valid linebreak sequence).When writing lines, I suggest to use
\r\n. It should work fine in all clients (webbrowsers).