Search code examples
stringjsfjsf-2primefaces

h:outputText line break for long words within strings


Is there a way to tell h:outputText of JSF (2.0) to insert a line break (or even better: A custom string like "-") into very long words within strings? My problem is that my data-table (PrimeFaces) gets too wide when I have a very long word within a string with no spaces. It works when I have a long text "normal" words, then the next word is printed in the next line.

While I could use a converter, this would still mean that I have to look for long words within a string and then cut them every time I display the text. This would work somehow for a small amount of data, but needs a lot of processing power when the database is getting bigger (and it will).

I also could scan the string for long words before inserting into the database, which would mean that I only have to process the string once, but also that i'm not able to fully reconstruct the original string if I'd ever need it.

Does anyone have any input on this?

Thank you in advance and best regards, Robert


Solution

  • Set CSS word-wrap property of the element in question to break-word.

    <h:outputText styleClass="someClass" />
    

    with

    .someClass {
        word-wrap: break-word;
    }