Diagram : elements displayed using "toString()" if facet contains conditional (rendered) blocks
See original GitHub issueDescribe the defect Say you want to customize how each element is displayed in the diagram by using “<p:outputPanel rendered=…” with the appropriate condition for each element.
If the facet only contains blocks like that with no unconditional block, then the facet displays element using “toString()” instead of the panel contents (even though the condition to render them is true)
Reproducer I’ve attached primefaces-test from your repository, including a simple test bean and facelet showing this issue primefaces-test.tar.gz
Environment:
- PF Version: 8.0
- JSF + version: Mojarra 2.2.20
- Affected browsers: ALL
To Reproduce Steps to reproduce the behavior:
-
Load “testView.jsf” in the attached sample
-
Elements’ “toString()” is used for display, see:
-
Place whatever contents inside the facet but outside the panel, even a simple empty “span” will suffice
-
Reload the page
-
The diagram displays just ok, see:
Expected behavior “rendered” conditions should be evaluated even if there is no contents outside any “rendered” conditioned block
Example XHTML This makes the facet to be displayed wrong
<h:body>
<p:diagram value="#{testView.model}" var="elem" style="height: 100vh">
<f:facet name="element">
<p:outputPanel rendered="#{not empty elem.name}">
<h:outputText value="#{elem.name}" />
</p:outputPanel>
</f:facet>
</p:diagram>
</h:body>
But this, makes it work. Note that I have only added an empty “span” outside any “rendered” block
<h:body>
<p:diagram value="#{testView.model}" var="elem" style="height: 100vh">
<f:facet name="element">
<span />
<p:outputPanel rendered="#{not empty elem.name}">
<h:outputText value="#{elem.name}" />
</p:outputPanel>
</f:facet>
</p:diagram>
</h:body>
All elements in the model have a non-empty name attribute Example Bean
@Named
@ViewScoped
public class TestView implements Serializable {
private DefaultDiagramModel model;
@PostConstruct
public void init() {
model = new DefaultDiagramModel();
Element elementA = new Element(new ElementData("A"), "20em", "6em");
Element elementB = new Element(new ElementData("B"), "10em", "18em");
Element elementC = new Element(new ElementData("C"), "40em", "18em");
model.addElement(elementA);
model.addElement(elementB);
model.addElement(elementC);
}
public DiagramModel getModel() {
return model;
}
public static class ElementData {
private final String name;
public ElementData(String name) {
this.name = name;
}
public String getName() {
return name;
}
public String toString() {
return "Lorem ipsum dolor sit amet, consectetur adipiscing elit. " +
"Curabitur efficitur ante mauris, vel ultricies neque lacinia et. " +
"Nullam urna erat, ullamcorper a nulla nec, auctor consequat erat. In sed mollis mi. " +
"Cras tristique ac orci sed luctus. Ut eu gravida lectus. Aenean dignissim, turpis convallis facilisis vestibulum, " +
"odio sapien tincidunt tortor, et lobortis erat quam sed felis. " +
"Praesent scelerisque nibh eget tempor egestas. In vitae arcu lectus. Nulla facilisi. " +
"Vestibulum quis cursus lorem, et mattis nisl. Ut posuere elit eget libero imperdiet consectetur. " +
"Nullam eu ornare tellus. Donec bibendum sapien maximus leo suscipit, sed varius sem malesuada. " +
"Maecenas vehicula ac ipsum non efficitur. Donec vitae fringilla quam, in congue neque. " +
"Pellentesque vel sem a lacus sagittis accumsan.";
}
}
}
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (5 by maintainers)
This is one of the best documented issues I have seen here in a long while. Just wanted to point that out.
Thank you very much everyone 😃 For the comments and the quick fix!!!
I Appreciate it.