I have a multi-line value in Resource.properties file:
TXT_ABOUT = first line \
second line \n \
third line.
I am displaying this in the About box:
<h:outputText value="#{txt.TXT_ABOUT}"/>
(The txt is defined via faces-config.xml:
<resource-bundle>
<base-name>com.compayn.etcetc.Resources</base-name>
<var>txt</var>
</resource-bundle>
but this is not important for the question.)
The problem is: new line marks in the variable definition are not shown on the rendered page, it's all in one row. Is this syntax above OK? Is \n OK?
You have to use backslash (\) at the end of the line. This question was already asked here.
Your problem is probably because HTML doesn't care about new line. If you want to display a new line you have to use the <br /> tag.
You can include HTML code in your properties file and the use the escape="false" to avoid escaping the HTML tags when generating the HTML.
TXT_ABOUT = first line<br />\
second line<br />\
third line.
JSF code:
<h:outputText value="#{txt.TXT_ABOUT}" escape="false" />
Related
I want to display the whole password requirements in the shortdesc attribute of Inputtext. But every time I pass a String, it is displaying the text in the same row.
For example I am attaching the code with 'hello world' as shortdesc.Below is the screen for the same:
I want 'hello' in one line and 'world' in another line.Can it be done?If yes, Can anyone help me.
Thanks in advance.
The only way that have worked for me is editing the proper underlying css class of the "shortDesc component" (AFNoteWindowShortDesc) in the skin file and reading the value with the breakline character from a managed bean if you want to control where to break each line:
In my css-skin file:
.AFNoteWindowShortDesc {
white-space: pre; /* To produce the line break */
}
In a managed bean:
private String multilineText = "Hello\nWorld";
public String getMultilineText() {
return multilineText;
}
Finally in the page fragment:
<af:inputText label="Multiline shortDesc in ADF" id="it1"
shortDesc="#{pageFlowScope.departmentManagedBean.multilineText}"/>
Result:
But if your shortDesc text is long and you only want it break automatically, then do this:
Skin file:
.AFNoteWindowShortDesc {
word-break: break-word;
}
Result:
It can be done by adding escape="false" and a <br/> in the middle of your shortDesc.
<af:inputText label="label" id="dc_it1" shortDesc="hello <br /> world" escape="false"/>
The escape=false allow the <br/> to not being HTML-escaped.
For more info see: How to put "new line" in JSP's Expression Language?
In my HTML I'm using paragraph that gets content by calling method via thymeleaf:
<p data-th-text="${fund.formatDescription()}"></p>
Method:
private String description;
public String formatDescription() {
return description.replace(";", " \n ");
}
I want my description to have end lines in palce of every semicolon. So that's why I added \n. But thymeleaf ingores new lines and returns continuous text. I tried adding <br/> but it ends up not interpreted as html. What should I add in place of semicolon to force new line in the description?
Html ignores newlines (this isn't thymeleaf's fault). You can either:
Put the description into <pre></pre> tags (or use the css white-space property on the <p> element).
Instead of replacing ; with \n, replace it with <br /> and use th:utext instead of data-th-text. (This means that html will be unescaped, so you better make sure users can't put other html into the description field or you open yourself up to html attacks).
I made a Thymeleaf dialect that makes it easy to keep the line breaks, if the css white-space property isn't an option.
It also bring support for BBCode if you want it.
You can either import it as a dependency (it's very light) or just use it as inspiration to make your own.
Check it out here :
https://github.com/oxayotl/meikik-project
I have some text which I want to have on separate lines.
I try to println this with label:
add(new Label("output",output));
<span wicket:id="output">Will be replaced</span>
Problem with this code it that it is ignoring formatting new line. Is there better way how to println some text?
There are two options:
Use a <pre /> (as in: preformatted) tag instead of <span />. If you have new line markers in your text, it will work, because browsers do not format text that is placed inside the <pre /> tag.
Use Wicket's MultiLineLabel class. After the Javadoc:
Unlike Label, MultiLineLabel shows text that spans multiple lines by inserting line breaks (BR tags) for newlines and paragraph markers (P tags) for sequences of more than one newline.
Note, that if using the MultiLineLabel class, you should not use a <span /> tag in your HTML, as placing paragraphs (<p />) inside <span /> is considered bad practice.
I am using \n in my java bean and output of the variable in console is displayed correctly. Whereas while fetching this value from bean to JSF \n seems not working.......
can any one suggest me how can i make \n work in of JSF.
The simplest way would be to apply CSS white-space: pre on the parent element containing the text of which you would like to preserve newline \n characters. Given this CSS style class:
.preformatted {
white-space: pre;
}
You could apply this as follows:
<div class="preformatted">#{bean.text}</div>
or
<h:panelGroup layout="block" styleClass="preformatted">#{bean.text}</h:panelGroup>
or
<h:outputText value="#{bean.text}" styleClass="preformatted" />
etc.
This style property is by the way also exactly what the <textarea> element is by default using. You could also make use of it and make it uneditable by setting disabled="true" or readonly="true".
<h:inputTextarea value="#{bean.text}" disabled="true" />
You can of course also replace all occurrences of \n by the HTML <br/> element. This way you can display it in an element which does not use white-space: pre and/or is not a <textarea> element. One of the ways is using fn:replace().
<h:outputText value="#{fn:replace(bean.text,'\\n','<br/>')}" escape="false" />
This is IMO only uglier than white-space: pre.
You should replace all \n with <br/> before you send the value to your <h:inputTextarea>.
Html uses <br/> for line break and not the \n like java.
Also, you should add escape="false" to your <h:outputText (almost sure...).
Replace all occurrences of \n with </br> before displaying it.
When looking into text recorded in my database via a <h:inputTextarea> I found that special characters were being persisted.
Thus, after investigating what I thought was some dark art of persistence, I appreciated that the default display of the JSF component was in fact what was letting me down.
I shortly found that adding white-space: pre-wrap; to <p> on my stylesheet fixed this problem for my <h:outputText> tags which were being supplied with text from a JPA pojo.
In my case, I needed pre-wrap rather than pre because pre was wrapping by character, rather than by word.
Hope this helps someone!
I have solved it using the following method
Declare an inputtextarea where a user can provide multi-line description. Before saving it to database, I have replaced new line to branch
String fpDescriptionCombined = fpDescription.replaceAll("(\r\n|\n)", "<br />");
During showing in screen, i again replaced branch to new line
String finalStr = splitStr.replaceAll("<br />", "\n");
In screen, I used above-mentioned CSS
.showLineBreak {
white-space: pre;
}
<h:outputText value="${templateListController.getFlowPointDescriptionForTab(eachFPType)}" style="display:block;width:860px;" styleClass="showLineBreak" />
I had to do this because my description can be exported/imported via csv. So adding multi-line description will be treated as a new record if not handled properly
I don't know how to escape ' in a java properties file. I'm using struts2 and getText function to fill i18n and text tags.
For example I use:
config.users.title= taula d'usuaris ---> config.users.title= taula d\'usuaris
But in my JSP, I get : taula dusuaris.
I use this to display text on my JSP:
<label for="title"><s:text name="config.users.title" />:</label>
Also I sometimes I use:
<s:select id="categories" name="categories" headerKey=""
headerValue="%{getText('map.categories.all')}"
list="categories" listKey="id" listValue="name"/>
What's the error?
Thanks!
Thanks lucentmind and BalusC foryour repliees
the solution was this: on my properties file I quoted ' as \'' and works fine.
**taula d \''usuaris**
Thanks
try to use double quote as escape character to show single quote on HTML page.
so you can mention value in propertis file like this : taula d "\'"usuaris