Jsf control that format text with html tags [duplicate] - jsf

This question already has an answer here:
Component to inject and interpret String with HTML code into JSF page
(1 answer)
Closed 6 years ago.
Good morning all.
Is there any jsf control that escapes the html tags?
Imagine that i have the following string in resources:
text.String=lalala<br/>lelele
and i want to print it on Xhtml file with a simple control like:
<h:outputText value="#{messages['text.String']}" />
how do i get the result formatted with the html <br/> tag?
Result should be:
lalala
lelele
instead of:
lalala<br/>lelele
Thanks

the outputText control has an 'escape' property which controls that behaviour.
See here (outputText reference).
So basically:
<h:outputText escape="false" value="#{messages['text.String']}" />
should do the job.

Related

how to add tooltip for selectItems tag in JSF [duplicate]

This question already has answers here:
How to add tooltip to f:selectItems
(2 answers)
Closed 6 years ago.
<h:selectOneMenu id="sType"value="#{sBean.sCriteria.sType}" style="width:200px;" styleClass="black" onchange="sTypeChanged();">
<f:selectItems value="#{sBean.allSTypes}" />
</h:selectOneMenu>
I am using the above code in my xhtml file.
I want to add "tool tip" in my selectOneMenu tag.
How can I do this?
Please look at this question hope ot helps
How to add tooltip to f:selectItems
Try ans use the title attributes best thing will be to bind the title in a map in the backing bean and use it here dynamically
Use the title attribute of selectOneMenu
<h:selectOneMenu id="sType"
title="tooltip_goes_here"
...
http://docs.oracle.com/javaee/5/javaserverfaces/1.2/docs/tlddocs/h/selectOneMenu.html

Using rendered with JSF [duplicate]

This question already has an answer here:
Why do I need to nest a component with rendered="#{some}" in another component when I want to ajax-update it?
(1 answer)
Closed 7 years ago.
How does rendered work? It hides h:form content completely and does not show it if expression.list is not empty.
<h:form id="stackForm" rendered="#{not empty expression.list}">
<p:orderList id="stack" value="#{expression.list}"...
...
It doesn't hide it - it doesn't render it at all, if rendered condition evaluates to false. In your case, if #{expression.list} is empty, form will not be rendered. Or, when rendered is translated to plain English, read it as Render the form if expression.list is not empty.

Component in JSF that preserve new lines and whitespaces [duplicate]

This question already has an answer here:
h:outputText seems to trim whitespace, how do I preserve whitespace?
(1 answer)
Closed 7 years ago.
Mojara 2.1.21, Primefaces 3.5, Omnifaces 1.5
Is it possible in JSF to use a component that preserve whitespaces and new lines ?
I have something like that:
<c:forEach items="{bean.items}" var="item">
<h:outputText value="#{item.text}" />
<p:inputText value="#{item.getText[item.id]}" />
</c:forEach >
Instead of staring at JSF source code, you should first investigate how the generated HTML output should look like in order to achieve the concrete UI requirement. In plain HTML terms, you can achieve that by either putting the text content in a HTML <pre> element, or to apply CSS white-space:pre style on the parent element.
None of them have a JSF component equivalent. But that's also not necessary. You can just write HTML and CSS the usual way in JSF.
<pre><h:outputText value="#{item.text}" /></pre>
or
<h:outputText value="#{item.text}" style="white-space: pre;" />
(note: above example is intented as kickoff, normal practice is to use a normal CSS class)

Setting a variable in JSF [duplicate]

This question already has an answer here:
How to use Parameterized MessageFormat with non-Value attributes of JSF components
(1 answer)
Closed 6 years ago.
I have something like this in my jsf:
<div title="Percentage: #{myBean.numberToBeConvertedToPercentage}"></div>
I wanted to make something like this:
<h:outputText value="#{myBean.numberToBeConvertedToPercentage}">
<f:convertNumber maxFractionDigits="2" type="percent"/>
</h:outputText>
Of course, not inside an output text, but instead setting the converted number to a variable, so I can use it inside my div.
I don't want to take this converted number direct from my bean, since I use it in another places of my view without formatting it, and creating a get just for this, I don't like the idea. There is any way to make this only in my view?
To go with <h:outputText> + converter, it is the best approach for this purpose in JSF. You can redesign your Html to separate the label "Percentage: " and the data. to use rendered value in JS code to pass it to 'title' attribute.
<div id="titleDiv" />
<script type="text/javascript">
$('#titleDiv').title = 'Percentage: <h:outputText value="#{myBean.numberToBeConvertedToPercentage}"><f:convertNumber maxFractionDigits="2" type="percent"/></h:outputText>';
</script>
If you still want to stay without converters, then you can create one more bean per your view and render values in get methods.
Other option is to use EL 2.2 Method call feature and to call your own format bean
<div title="Percentage: #{formatBean.formatNumber(myBean.numberToBeConvertedToPercentage, 2)}"></div>
I have not checked this, but maybe you can use ui:param and assign a converter to it.
and then use it in your page
<div title="Percentage: #{myVar}></div>
see Defining and reusing an EL variable in JSF page

How to display html code which is load from db in jsf screen? [duplicate]

This question already has an answer here:
Component to inject and interpret String with HTML code into JSF page
(1 answer)
Closed 6 years ago.
I have html code in one column. Loaded html code to one bean.
My question is how to display this html code using jsf tags.
You can use a <h:outputText> component, and set escape="false".

Resources