string h:outputText 字符串中长单词的换行符
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4556980/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
h:outputText line break for long words within strings
提问by Robert M.
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.
有没有办法告诉h:outputText
JSF (2.0) 将换行符(或者甚至更好:像“-”这样的自定义字符串)插入字符串中很长的单词中?我的问题是我的数据表 (PrimeFaces) 在没有空格的字符串中有一个很长的单词时变得太宽。当我有一个长文本“正常”单词时它起作用,然后下一个单词打印在下一行。
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
提前致谢并致以最诚挚的问候,罗伯特
回答by BalusC
回答by Jigar Joshi
<h:outputText value="Very Wordy<br />Table Column<br />Heading" escape="false" />
Output
输出
Very Wordy
Table Column
Heading
回答by Pramod Kankure
This can be accomplished by two steps
这可以通过两个步骤来完成
1)Apply style as table-layout:fixed to the panelGrid
1)将样式应用为表格布局:固定到panelGrid
E.g:<h:panelGrid style="table-layout:fixed;">
例如:<h:panelGrid style="table-layout:fixed;">
2) Then apply style of word-wrap break-word to the <h:outputText />
as below.
2)然后将自动换行断字的样式应用于<h:outputText />
如下。
E.g:<h:outputText style="word-wrap:break-word;">
例如:<h:outputText style="word-wrap:break-word;">
Hope this helps.
希望这可以帮助。
回答by Silence
if you have very long word in String you can use word-break: break-all;
like this:
如果你在字符串中有很长的单词,你可以这样使用word-break: break-all;
:
<h:outputText value="111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111" style="word-break: break-all;"/>
but it required CSS3. link: word-break
但它需要 CSS3。链接:断字
回答by Ebrahim Amini Sharifi
you can use h:inputTextarea rather than h:outputText , don't remember set readonly attribute true and remove border like this:
您可以使用 h:inputTextarea 而不是 h:outputText ,不要记住将 readonly 属性设置为 true 并删除边框,如下所示:
<h:inputTextarea rows="10" cols="50" readonly="true" value="multiline String" style="border-color: white" />