Friday, June 27, 2008

Text break in jsp / html

Many of us face the problem of breaking the string which is dynamically generated, in html / jsp.For example the following the code will give you the problem of not wrapping the sentence in the table cell.

<table><tbody><tr><td>Name:</td> <td>BALAKRISHNAN;BALAKRISHNAN;BALAKRISHNAN;BALAKRISHNAN;BALAKRISHNAN;BALAKRISHNAN;BALAKRISHNAN;BALAKRISHNAN;BALAKRISHNAN;BALAKRISHNAN;BALAKRISHNAN;BALAKRISHNAN;BALAKRISHNAN;BALAKRISHNAN;BALAKRISHNAN;BALAKRISHNAN;BALAKRISHNAN;BALAKRISHNAN;BALAKRISHNAN;BALAKRISHNAN;BALAKRISHNAN;BALAKRISHNAN; </td></tr></tbody></table>

The reason is html engine wraps the content when there is a space in between the words. To avoid this just add this style in your table cell style="WORD-BREAK:BREAK-ALL;"

Modified code is

<table><tbody><tr><td>Name:</td> <td style="WORD-BREAK:BREAK-ALL;"> BALAKRISHNAN;BALAKRISHNAN;BALAKRISHNAN;BALAKRISHNAN;BALAKRISHNAN;BALAKRISHNAN;BALAKRISHNAN;BALAKRISHNAN;BALAKRISHNAN;BALAKRISHNAN;BALAKRISHNAN;BALAKRISHNAN;BALAKRISHNAN;BALAKRISHNAN;BALAKRISHNAN;BALAKRISHNAN;BALAKRISHNAN;BALAKRISHNAN;BALAKRISHNAN;BALAKRISHNAN;BALAKRISHNAN;BALAKRISHNAN; </td></tr></tbody></table>

No comments: