You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by hn...@apache.org on 2024/02/12 10:25:57 UTC
(myfaces-tobago) branch main updated: feature(sheet): empty facet
This is an automated email from the ASF dual-hosted git repository.
hnoeth pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/myfaces-tobago.git
The following commit(s) were added to refs/heads/main by this push:
new 423c681c09 feature(sheet): empty facet
423c681c09 is described below
commit 423c681c09ecb7fce72be6d3c0e27c7986dd8fa6
Author: Henning Noeth <hn...@apache.org>
AuthorDate: Mon Feb 12 09:07:06 2024 +0100
feature(sheet): empty facet
Add an empty facet to change the "no rows available"-message of an empty sheet.
Add also an example
Issue: TOBAGO-2286
---
.../apache/myfaces/tobago/component/Facets.java | 2 +
.../internal/renderkit/renderer/SheetRenderer.java | 13 ++--
.../tobago/example/demo/SheetController.java | 5 ++
.../content/080-sheet/43-empty/Empty_Sheet.xhtml | 84 ++++++++++++++++++++++
4 files changed, 100 insertions(+), 4 deletions(-)
diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/component/Facets.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/component/Facets.java
index 6a37bb35b5..270a64b5ae 100644
--- a/tobago-core/src/main/java/org/apache/myfaces/tobago/component/Facets.java
+++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/component/Facets.java
@@ -33,6 +33,7 @@ public enum Facets {
*/
@Deprecated
contextMenu,
+ empty,
footer,
label,
header,
@@ -55,6 +56,7 @@ public enum Facets {
*/
@Deprecated
public static final String CONTEXT_MENU = "contextMenu";
+ public static final String EMPTY = "empty";
public static final String FOOTER = "footer";
public static final String LABEL = "label";
public static final String HEADER = "header";
diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/SheetRenderer.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/SheetRenderer.java
index e4c8921936..6e4d7ce01f 100644
--- a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/SheetRenderer.java
+++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/SheetRenderer.java
@@ -758,10 +758,15 @@ public class SheetRenderer<T extends AbstractUISheet> extends RendererBase<T> {
}
writer.startElement(HtmlElements.TD);
writer.writeAttribute(HtmlAttributes.COLSPAN, countColumns);
- writer.startElement(HtmlElements.DIV);
- writer.writeClassAttribute(BootstrapClass.TEXT_CENTER);
- writer.writeText(ResourceUtils.getString(facesContext, "sheet.empty"));
- writer.endElement(HtmlElements.DIV);
+ final UIComponent emptyFacet = ComponentUtils.getFacet(sheet, Facets.empty);
+ if (emptyFacet != null) {
+ emptyFacet.encodeAll(facesContext);
+ } else {
+ writer.startElement(HtmlElements.DIV);
+ writer.writeClassAttribute(BootstrapClass.TEXT_CENTER);
+ writer.writeText(ResourceUtils.getString(facesContext, "sheet.empty"));
+ writer.endElement(HtmlElements.DIV);
+ }
writer.endElement(HtmlElements.TD);
if (!autoLayout) {
writer.startElement(HtmlElements.TD);
diff --git a/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/SheetController.java b/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/SheetController.java
index 78726b3771..51a3cf28bc 100644
--- a/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/SheetController.java
+++ b/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/SheetController.java
@@ -77,6 +77,7 @@ public class SheetController implements Serializable {
private SheetState lazyTwoState;
private int actionCount = 0;
private int actionListenerCount = 0;
+ private List<SolarObject> emptyList = new ArrayList<>();
@PostConstruct
private void init() {
@@ -196,4 +197,8 @@ public class SheetController implements Serializable {
public int getActionListenerCount() {
return actionListenerCount;
}
+
+ public List<SolarObject> getEmptyList() {
+ return emptyList;
+ }
}
diff --git a/tobago-example/tobago-example-demo/src/main/webapp/content/080-sheet/43-empty/Empty_Sheet.xhtml b/tobago-example/tobago-example-demo/src/main/webapp/content/080-sheet/43-empty/Empty_Sheet.xhtml
new file mode 100644
index 0000000000..49b63f235c
--- /dev/null
+++ b/tobago-example/tobago-example-demo/src/main/webapp/content/080-sheet/43-empty/Empty_Sheet.xhtml
@@ -0,0 +1,84 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+-->
+
+<ui:composition template="/main.xhtml"
+ xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:f="jakarta.faces.core"
+ xmlns:tc="http://myfaces.apache.org/tobago/component"
+ xmlns:ui="jakarta.faces.facelets">
+ <p>If a sheet contains an empty list, a "no rows available"-message is displayed by default.
+ The default can be changed with an <code class="language-markup"><f:facet name="empty"></code> tag.</p>
+
+ <tc:section label="Default">
+ <p>This is the default behavior if the sheet has no entry.</p>
+ <tc:sheet id="default" value="#{sheetController.emptyList}" var="object" rows="4">
+ <tc:style maxHeight="500px"/>
+ <tc:column label="Name">
+ <tc:out value="#{object.name}" labelLayout="skip"/>
+ </tc:column>
+ <tc:column label="Orbit">
+ <tc:out value="#{object.orbit}" labelLayout="skip"/>
+ </tc:column>
+ <tc:column label="Period (Days)">
+ <tc:out value="#{object.period}" labelLayout="skip"/>
+ </tc:column>
+ <tc:column label="Discoverer">
+ <tc:out value="#{object.discoverer}" labelLayout="skip"/>
+ </tc:column>
+ <tc:column label="Year">
+ <tc:out value="#{object.discoverYear}" labelLayout="skip"/>
+ </tc:column>
+ </tc:sheet>
+ </tc:section>
+
+ <tc:section label="Custom">
+ <p>This sheet uses the empty-facet.</p>
+ <demo-highlight language="markup"><f:facet name="empty">
+ <tc:panel>
+ <tc:style customClass="empty-sheet-indicator"/>
+ <tc:out value="This sheet has no entry. This is a custom message." plain="true"/>
+ </tc:panel>
+</f:facet>
+ </demo-highlight>
+ <tc:sheet id="facet" value="#{sheetController.emptyList}" var="object" rows="4">
+ <tc:style maxHeight="500px"/>
+ <tc:column label="Name">
+ <tc:out value="#{object.name}" labelLayout="skip"/>
+ </tc:column>
+ <tc:column label="Orbit">
+ <tc:out value="#{object.orbit}" labelLayout="skip"/>
+ </tc:column>
+ <tc:column label="Period (Days)">
+ <tc:out value="#{object.period}" labelLayout="skip"/>
+ </tc:column>
+ <tc:column label="Discoverer">
+ <tc:out value="#{object.discoverer}" labelLayout="skip"/>
+ </tc:column>
+ <tc:column label="Year">
+ <tc:out value="#{object.discoverYear}" labelLayout="skip"/>
+ </tc:column>
+ <f:facet name="empty">
+ <tc:panel>
+ <tc:style customClass="empty-sheet-indicator"/>
+ <tc:out value="This sheet has no entry. This is a custom message." plain="true"/>
+ </tc:panel>
+ </f:facet>
+ </tc:sheet>
+ </tc:section>
+</ui:composition>