Primefaces global tooltip with HTML content - html

In my JSF page I am using a datatable with tooltip on a row column like this:
<p:dataTable var="item" ...>
<p:column headerText="#{bundle['item.name']}">
<!--
<h:outputText value="#{item.name}" title="#{simpleTooltipGenerator.generate(item)}"/>
-->
<h:outputText id="name" value="#{item.name}"/>
<p:tooltip for="name" escape="false" value="#{simpleTooltipGenerator.generate(item)}"/>
</p:column>
</p:dataTable>
The simpleTooltipGenerator.generate() is a method which generates the following HTML tooltip:
<div class="ui-tooltip-text ui-shadow ui-corner-all">
<table>
<tbody>
<tr><td class="key">Lastname</td><td class="value">Doe</td></tr>
<tr><td class="key">Firstname</td><td class="value">John</td></tr>
</tbody>
</table>
<div class="adresse spacer"></div>
<div class="adresse title">Address</div>
<table>
<tbody>
<tr><td class="key">OFFICE</td><td class="value">...</td></tr>
<tr><td class="key">HOME</td><td class="value">...</td></tr>
</tbody>
</table>
</div>
This works as expected, but when I use a global tooltip <p:tooltip escape="false"/> together with <h:outputText value="#{item.name}" title="#{simpleTooltipGenerator.generate(item)}"/> only the generated HTML code is shown in the tooltip! Using a fixed text for the global tooltip works?!
Is this a bug, that global tooltip does not support HTML content, even if set escape="false", or is this not supported?!
My environment is Primefaces 6.0 on WildFly 10.0.0-Final

From PrimeFaces Documentation:
Global Tooltip
...
As global tooltips are more efficient
since only one instance of tooltip is used across all tooltip targets, it is suggested to be used instead
of explicit tooltips unless you have a custom case e.g. different options, custom content.
First I would say this is not supported. As i tried it worked nevertheless. So your problem seems to be missing globalSelector attribute which defaults to a,:input,:button
If you want to support <h:outputText /> (which renders as <span />) binding, just add a propper selector like:
<p:tooltip escaped="false" globalSelector="a,:input,:button,span" />

Related

Add icon (e.g. material design or Prime Icons) to a p:inputText

I want to add an icon for an input text element, in a JavaEE project:
<h:panelGroup styleClass="md-inputfield">
<p:inputText id="name"
value="#{createCustomerView.customer.name}" required="true"
label="Nome" requiredMessage="inserisci il nome">
<f:validateLength minimum="2" />
</p:inputText>
<p:outputLabel for="name" value="Nome" />
<p:message for="name" display="icon" />
</h:panelGroup>
How Can add an icon, like a person icon?
You can make use of Primefaces input group. refer https://www.primefaces.org/showcase/ui/input/inputGroup.xhtml
<div class="ui-inputgroup">
<span class="ui-inputgroup-addon"><i class="pi pi-user"></i></span>
<p:inputText placeholder="Username" />
</div>
But don't forget you do need to add the PrimeIcons by adding this to your h:head
(like mentioned in https://www.primefaces.org/showcase/ui/misc/primeicons.xhtml)
Please note that the input group is not a component, but a set of CSS rules. Those rules where added in PrimeFaces 7. If you are using an older version of PrimeFaces, it's a good idea to upgrade for many other reasons, but if you really cannot, you can always add the CSS rules to your own project as custom styles.
Alternatively, you should remember that JSF / PrimeFaces will simply render HTML. So you can always resort to a solution using CSS, as can be found at: Put icon inside input element in a form.
See also:
How do I override default PrimeFaces CSS with custom styles?

How can I display line breaks (as entered in inputTextArea) in a jsf datatable?

Here is an simplified code sample, for what I'm trying to do. A text entered above in an inputTextArea is correctly displayed (with Line Breaks).
Below, in the dataTable, the same text is displayed without Line breaks.
<h:form id=myInputText#{id}>
<h:inputTextarea id="myInputText" value="#{form.textWithLinebreaks}"/>
</h:form>
<h:form id=myOutput>
<rich:dataTable
id="myTable"
value="#{form.model}"
var="f"
style="table-layout: fixed;"
styleClass="wordWrap"
rows="5">
<a4j:support event="onRowClick"
action="#{action.selectText(f)}"
immediate="true" reRender="myInputText#{id}" />
<rich:column>
<f:facet name="header">
TextShouldHaveLineBreaks
</f:facet>
<h:outputText value="#{f.text}"/>
</rich:column>
</rich:dataTable>
</h:form>
Things I tried to fix this:
<h:outputText value="#{f.text}" style="white-space: pre-wrap"/>
doesn't Change anything.
I also tried using a readonly inputTextArea as a workaound:
<rich:column>
<f:facet name="header">
TextShouldHaveLineBreaks
</f:facet>
<h:inputTextarea value="#{f.text}" style="white-space: pre-wrap" readonly="true"/>
</rich:column>
This doesn't help either, and will require lots of css to look just like all other columns.
Just in case this is relevant: My application runs on Seam with Richfaces 3.3.

Best way to show a primefaces p:tooltip on page load

I want to open a tooltip when page loads for first time... somehow just like a help guide for first time use opens the page, not waiting for him to hover mouse on the object.
Best approach?
thanks
You can use the onload attribute in the body tag:
<h:body onload="PF('tip1').show();">
<h:form>
<p:inputText id="txt" title="Type something into this field"/>
<p:tooltip for="txt" widgetVar="tip1" value="tooltip text"/>
</h:form>
</h:body>
You can use PrimeFaces Extensions Auto Shown tooltip
Download jar file from: primefaces-extensions-6.0.0.jar
namespace:
xmlns:pe="http://primefaces.org/ui/extensions"
usage:
<h:panelGrid id="details" columns="2">
<h:outputLabel value="Tooltip on InputText: "/>
<h:panelGroup layout="block" style="padding: 0 0 3px 0;">
<p:inputText id="txt" title="Type something into this field"/>
<pe:tooltip for="txt" autoShow="true" widgetVar="tip1"
myPosition="left center" atPosition="right center"/>
</h:panelGroup>

Primefaces 5.1 show tooltip on single cell of a datatable for each row without extensions

I faced a problem with primefaces and tooltip on a single cell column.I was not able to use it so I searched the web and I found many answer like this one. the first answer did not solved the problem, infact that did nothing at all and the second one gave me error at runtime, telling me that it cannot find the righ object in the page.
So,how can i use a tooltip on a single cell of a table for each row?
I'm using primefaces 5.1, jsf 2.2, java 1.6.
despite many answers that suggest you to use primefaces extensions, the only thing you have to do to see your tooltip is to use primefaces itself like this:
<p:tooltip id="toolTipGrow" value="#{row.property}" shared="true" for="idField" showEffect="clip" position="top"/>
where idField is the id from which you want to see the tooltip appear and row.property is the value that you want to show into it.
the thing is now simple to make. here it is an example with the datatable:
<p:dataTable var="row" value="#{....}" styleClass="myTable">
<p:column headerText="Header 2">
<h:outputText value="#{row.value2}" id="idField" />
<p:tooltip id="toolTipGrow" value="#{row.property}" shared="true" for="idField" showEffect="clip" position="top"/>
</p:column>
</p:dataTable>
I hope this will help.
Best Regards
Yes its possible. See..
<p:column>
<f:facet name="header">
<h:outputText
id="header"
value="Header"
/>
<p:tooltip
for="header"
showEffect="fade"
hideEffect="fade"
>
<!-- content of tooltip for header -->
</p:tooltip>
</f:facet>
<h:outputText
id="col"
value="#{object.valueA}"
/>
<p:tooltip
for="col"
showEffect="fade"
hideEffect="fade"
>
<!-- content of tooltip for cell -->
</p:tooltip>
</p:column>
In my scenario, I have all my data in cells inside h:outputText elements.
In that case, you can then use the title attribute.
<p:column>
<h:outputText value="#{row.data}" title="#{row.data}"/>
</p:column>

Unable to locate plain HTML element from <f:ajax render="...">

I have table that display equipments. There is a button below to enter page number for pagination. when click on that button ajax call updates the tableId table. But I have an error <f:ajax> contains an unknown id 'tableId'
Can't I refer table ID from ajax update? if not what is the solution? I cannot use datatable as I need to manupulate the column headings at runtime.
<table id="tableId">
<tr>
<td>
<h:commandLink ...>
<f:ajax render="tableId" />
</h:commandLink>
</td>
</tr>
</table>
The <f:ajax render> (and <f:ajax execute>) has to refer a fullworthy JSF component, not a plain HTML element. JSF will namely pass the specified ID to UIComponent#findComponent() in order to find in the component tree the component responsible for producing the desired piece of HTML output. A plain HTML element is not interpreted as a true JSF component and therefore not present by its ID in the JSF component tree.
Either make it a true JSF component,
<h:panelGrid id="tableId" columns="1">
<h:commandLink ...>
<f:ajax render="tableId" />
</h:commandLink>
</h:panelGrid>
or wrap it in a true JSF component and reference it instead.
<h:panelGroup id="tableIdWrapper" layout="block">
<table id="tableId">
<tr>
<td>
<h:commandLink ...>
<f:ajax render="tableIdWrapper" />
</h:commandLink>
</td>
</tr>
</table>
</h:panelGroup>