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?
Related
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 need to call a method from a java bean that returns a string composed of multiple lines
However I need to insert the newline character in the JSP Form.
In java bean, I am using the following method:
for (String s : descriptionContrats){
if(s.startsWith("Contrat")){
contratsBuilder.append(s+"\r\n ");
}
}
contrats=contratsBuilder.toString();
I wish to display the string contrats in multiple lines according to the number of iterations
But when the variable is called in JSP and I use it in the following manner:
<tr><td><%- contrats %> </td></tr>
It prints simply as a single string in a single line.
Update
I have already replaced contratsBuilder.append(s+"\r\n "); by contratsBuilder.append(s).append("<br/>"); but my <br /> tags getting converted to <br /> in the html. However when it renders on browser, it has the <br /> and therefore there is no line break???.
You are displaying the page in HTML, so you need to use HTML's newline tag - <br/>:
for (String s : descriptionContrats) {
if (s.startsWith("Contrat")) {
contratsBuilder.append(s).append("<br/>");
}
}
contrats = contratsBuilder.toString();
I have a web application running Java Tapestry, with a lot of user-inputted content. The only formatting that users may input is linebreaks.
I call a text string from a database, and output it into a template. The string contains line breaks as /r, which I replace with < br >. However, these are filtered on output, so the text looks like b<br>text text b<br> text. I think I can use outputRaw or writeRaw to fix this, but I can't find any info for how to add outputRaw or writeRaw to a Tapestry class or template.
The class is:
public String getText() {
KMedium textmedium = getTextmedium();
return (textmedium == null || textmedium.getTextcontent() == null) ? "" : textmedium.getTextcontent().replaceAll("\r", "<br>");
}
The tml is:
<p class="categorytext" id="${currentCategory.id}">
${getText()}
</p>
Where would I add the raw output handling to have my line breaks display properly?
To answer my own question, this is how to output the results of $getText() as raw html:
Change the tml from this:
<p class="categorytext" id="${currentCategory.id}">
${getText()}
</p>
To this:
<p class="categorytext" id="${currentCategory.id}">
<t:outputraw value="${getText()}"/>
</p>
Note that this is quite dangerous as you are likely opening your site to an XSS attack. You may need to use jsoup or similar to sanitize the input.
An alternative might be:
<p class="categorytext" id="${currentCategory.id}">
<t:loop source="textLines" value="singleLine">
${singleLine} <br/>
</t:loop>
</p>
This assumes a a getTextLines() method that returns a List or array of Strings; it could use the same logic as your getText() but split the result on CRs. This would do a better job when the text lines contain unsafe characters such as & or <. With a little more work, you could add the <br> only between lines (not after each line) ... and this feels like it might be a nice component as well.
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
In my web application (my first with Java, Spring, OR Roo), I'm building a form that has nothing to do with any JPA objects, it's just a form. I really don't want to use JSTL to build my forms here, because there's no data backing for them at this point. I'm using tiles to assemble the pages, so the guts of this form comes from a view, but apart from that there's nothing JSPish about it; it's just a form.
Inside that form, I have a text area that I've written:
<textarea id="whatever" name="whatever"></textarea>
When that comes to the screen, the </textarea> tag is gone. Different browsers deal with that differently, up to and including swallowing up the whole rest of the body HTML inside the text area field.
So I tried putting some content inside that textarea. Spaces and line breaks don't change its behavior, but it appears that any non-space character does. If I go
<textarea>.</textarea>
... it respects my close textarea tag. But then of course my text area renders on the screen with a dot in it, which isn't what I want.
Is this a known issue? Am I doing something wrong?
EDIT:
#bozho: Here's a pertinent chunk of my jsp:
<div id="notes" class="detailPanel">
<div class="panelLabel">Notes</div>
<table >
<thead><tr><th>Date</th><th>By</th><th>Note</th></tr></thead>
<tbody id="notesBody"></tbody>
</table>
<textarea id="newNote" rows="5" cols="80" >.</textarea>
<button id="addNewNote" onClick="saveNote();">Add New Note</button>
</div>
Absolutely nothing fancy going on here (I populate the tbody with rows on the client, is why that's empty). Without the dot in the third-to-last line, the closing textarea tag does not come out in the resulting HTML.
EDIT2 (Solution):
This URL became googlable after hearing some key words from people responding here:
http://www.jroller.com/komu/entry/textareas_with_jspx
Turns out that when jspx pages are parsed, empty tags are collapsed into a single self-closing tag, which breaks text areas. The solution is to put an empty jsp:text in the middle:
<textarea><jsp:text /></textarea>
(Which is STAGGERINGLY stupid, but there it is.)
You are using jspx files right?
In general jspx remove something (or in your case it shorten it: check this: I expect that it addes a slash to the former opening tag, so it becomes: <textarea id="whatever" name="whatever"/> ) where it belives that is not needed. What exactly depends ona bit on the implementation.
So put a <jsp:text> tag in the text area tag to prevent it from "closing"
<jsp:text>
<textarea id="whatever" name="whatever"></textarea>
</jsp:text>
<textarea id="whatever" name="whatever"><jsp:text /></textarea>
for an more complex example have a look at this answer: websphere 7 (and Spring Roo) incompatible with javax.el.ELException