Notification with longer text do not wrap and there is no way to read it if it is longer than the screen width.
If we put
in the middle, it breaks into the next line but this is not practical because text length is unknown at the time of writing the code. (Example: An error message from the database is unknown at the time of writing the code).
Hi,
This is a known issue currently, and a ticket has been made to fix it, most likely in 6.2:
http://dev.vaadin.com/ticket/2632
Thanks for reporting!
Thanks Jouni.
For the time being, I am inserting “
” into the text of the error message.
showNotification(caption, split(message, 60), …)
The split method looks something like this:
public static String split(String s, int length) {
if(s == null) { // Lazy guys may invoke me with nulls too!
return "";
}
if(s.indexOf('\r') >= 0) { // I don't want those ones from the Winso$ world!
s.replaceAll("\\r", "");
}
int pos = s.indexOf('\n'); // Break at newline anyway
if(pos >= 0) {
return split(s.substring(0, pos), length) + "<BR/>" + split(s.substring(pos + 1), length);
}
s = s.trim();
if(s.length() <= length || length <= 0) { // Already small or invalid length specified
return s;
}
pos = length;
while(pos >= 0) { // Try to split at whitespace at or before the length
if(Character.isWhitespace(s.charAt(pos))) {
return s.substring(0, pos).trim() "<BR/>" + split(s.substring(pos + 1), length);
}
--pos;
}
// No whitespace found, just split
return s.substring(0, length) + "<BR/>" + split(s.substring(length), length);
}
Feel free to copy the code if someone wants to use it.
Wow… This really emphasized why
http://dev.vaadin.com/ticket/2632
should be fixed soon.