You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lo...@apache.org on 2022/07/22 14:08:15 UTC
[myfaces-tobago] branch master updated: fix: AbstractUIData.findComponent() patch
This is an automated email from the ASF dual-hosted git repository.
lofwyr pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/myfaces-tobago.git
The following commit(s) were added to refs/heads/master by this push:
new 5e27566e2a fix: AbstractUIData.findComponent() patch
5e27566e2a is described below
commit 5e27566e2a42521e81a1cdec60c51f461a27494b
Author: Udo Schnurpfeil <ud...@irian.eu>
AuthorDate: Fri Jul 22 12:20:46 2022 +0200
fix: AbstractUIData.findComponent() patch
issue: TOBAGO-2154
---
.../tobago/internal/component/AbstractUIData.java | 26 +++++++++++
.../tobago/internal/component/AbstractUIPage.java | 12 +++--
.../tobago/internal/component/AbstractUISheet.java | 52 ++++------------------
.../tobago/example/demo/SheetActionController.java | 48 ++++++++++++++++++++
.../content/080-sheet/32-action/Sheet_Action.xhtml | 39 ++++++++++++++++
5 files changed, 131 insertions(+), 46 deletions(-)
diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUIData.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUIData.java
index cd5cc5d5f5..f8247ffa88 100644
--- a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUIData.java
+++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUIData.java
@@ -32,6 +32,7 @@ import org.slf4j.LoggerFactory;
import jakarta.faces.FacesException;
import jakarta.faces.component.ContextCallback;
import jakarta.faces.component.UIComponent;
+import jakarta.faces.component.UINamingContainer;
import jakarta.faces.component.visit.VisitCallback;
import jakarta.faces.component.visit.VisitContext;
import jakarta.faces.context.FacesContext;
@@ -194,6 +195,31 @@ public abstract class AbstractUIData extends jakarta.faces.component.UIData impl
return false;
}
+ @Override
+ public UIComponent findComponent(final String searchId) {
+ final String expr = stripRowIndex(searchId);
+ LOG.info("searchid '{}'" , searchId);
+ LOG.info("expr '{}'" , expr);
+ return super.findComponent(expr);
+ }
+
+ public String stripRowIndex(final String initialSearchId) {
+ String searchId = initialSearchId;
+ if (searchId.length() > 0 && Character.isDigit(searchId.charAt(0))) {
+ for (int i = 1; i < searchId.length(); ++i) {
+ final char c = searchId.charAt(i);
+ if (c == UINamingContainer.getSeparatorChar(getFacesContext())) {
+ searchId = searchId.substring(i + 1);
+ break;
+ }
+ if (!Character.isDigit(c)) {
+ break;
+ }
+ }
+ }
+ return searchId;
+ }
+
@Override
public boolean invokeOnComponent(
final FacesContext facesContext, final String clientId, final ContextCallback callback)
diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUIPage.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUIPage.java
index 1e16c8f7ab..dd0db9c179 100644
--- a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUIPage.java
+++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUIPage.java
@@ -96,9 +96,11 @@ public abstract class AbstractUIPage extends AbstractUIFormBase implements Clien
LOG.warn("No sourceId found!");
}
- // TODO: remove this if block if proven this never happens anymore
+ // TODO: Remove this if block if proven this never happens anymore
+ // TODO: This workaround is stil needed for Mojarra
+ // TODO: Otherwise actions in tree/sheet will not be detected
if (command == null
- && sourceId != null && sourceId.matches(".*:\\d+:.*")) {
+ && sourceId != null && sourceId.matches(".*:\\d+:.*")) {
// If currentActionId component was inside a sheet the id contains the
// rowIndex and is therefore not found here.
// We do not need the row here because we want just to find the
@@ -120,7 +122,11 @@ public abstract class AbstractUIPage extends AbstractUIFormBase implements Clien
if (command != null) {
final AbstractUIFormBase form = ComponentUtils.findForm(command);
- form.setSubmitted(true);
+ if (form != null) {
+ form.setSubmitted(true);
+ } else {
+ LOG.warn("No form found - this actually can not happen, because there is a form on each page!");
+ }
if (LOG.isTraceEnabled()) {
LOG.trace("form:{}", form);
diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUISheet.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUISheet.java
index d4693ef83f..bffc4981a8 100644
--- a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUISheet.java
+++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUISheet.java
@@ -19,14 +19,17 @@
package org.apache.myfaces.tobago.internal.component;
+import jakarta.el.ELContext;
+import jakarta.el.MethodExpression;
+import jakarta.el.ValueExpression;
+import jakarta.faces.component.UIColumn;
+import jakarta.faces.component.UIComponent;
+import jakarta.faces.component.behavior.ClientBehaviorHolder;
+import jakarta.faces.context.FacesContext;
+import jakarta.faces.event.*;
import org.apache.myfaces.tobago.component.Attributes;
import org.apache.myfaces.tobago.component.Visual;
-import org.apache.myfaces.tobago.event.PageActionEvent;
-import org.apache.myfaces.tobago.event.SheetStateChangeEvent;
-import org.apache.myfaces.tobago.event.SheetStateChangeListener;
-import org.apache.myfaces.tobago.event.SheetStateChangeSource;
-import org.apache.myfaces.tobago.event.SortActionEvent;
-import org.apache.myfaces.tobago.event.SortActionSource;
+import org.apache.myfaces.tobago.event.*;
import org.apache.myfaces.tobago.internal.layout.Grid;
import org.apache.myfaces.tobago.internal.layout.OriginCell;
import org.apache.myfaces.tobago.internal.util.SortingUtils;
@@ -41,21 +44,6 @@ import org.apache.myfaces.tobago.util.ComponentUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import jakarta.el.ELContext;
-import jakarta.el.MethodExpression;
-import jakarta.el.ValueExpression;
-import jakarta.faces.component.UIColumn;
-import jakarta.faces.component.UIComponent;
-import jakarta.faces.component.UINamingContainer;
-import jakarta.faces.component.behavior.ClientBehaviorHolder;
-import jakarta.faces.context.FacesContext;
-import jakarta.faces.event.AbortProcessingException;
-import jakarta.faces.event.ComponentSystemEvent;
-import jakarta.faces.event.ComponentSystemEventListener;
-import jakarta.faces.event.FacesEvent;
-import jakarta.faces.event.ListenerFor;
-import jakarta.faces.event.PhaseId;
-import jakarta.faces.event.PreRenderComponentEvent;
import java.io.IOException;
import java.lang.invoke.MethodHandles;
import java.util.ArrayList;
@@ -475,28 +463,6 @@ public abstract class AbstractUISheet extends AbstractUIData
removeFacesListener(listener);
}
- @Override
- public UIComponent findComponent(final String searchId) {
- return super.findComponent(stripRowIndex(searchId));
- }
-
- public String stripRowIndex(final String initialSearchId) {
- String searchId = initialSearchId;
- if (searchId.length() > 0 && Character.isDigit(searchId.charAt(0))) {
- for (int i = 1; i < searchId.length(); ++i) {
- final char c = searchId.charAt(i);
- if (c == UINamingContainer.getSeparatorChar(getFacesContext())) {
- searchId = searchId.substring(i + 1);
- break;
- }
- if (!Character.isDigit(c)) {
- break;
- }
- }
- }
- return searchId;
- }
-
public void performPaging(final PageActionEvent pageEvent) {
int first;
diff --git a/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/SheetActionController.java b/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/SheetActionController.java
new file mode 100644
index 0000000000..59a223c2c7
--- /dev/null
+++ b/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/SheetActionController.java
@@ -0,0 +1,48 @@
+/*
+ * 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.
+ */
+
+package org.apache.myfaces.tobago.example.demo;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import jakarta.enterprise.context.ApplicationScoped;
+import jakarta.faces.application.FacesMessage;
+import jakarta.faces.context.FacesContext;
+import jakarta.inject.Named;
+import java.io.Serializable;
+import java.lang.invoke.MethodHandles;
+
+@ApplicationScoped
+@Named
+public class SheetActionController implements Serializable {
+
+ private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+
+ public String deleteAction(final SolarObject solarObject) {
+
+ LOG.info("deleteAction called for {}, but we do not delete objects here in this demo.", solarObject.getName());
+
+ FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_WARN,
+ "We do not delete in this demo! (object='" + solarObject.getName() + "')", null));
+
+ return null;
+ }
+
+}
diff --git a/tobago-example/tobago-example-demo/src/main/webapp/content/080-sheet/32-action/Sheet_Action.xhtml b/tobago-example/tobago-example-demo/src/main/webapp/content/080-sheet/32-action/Sheet_Action.xhtml
new file mode 100644
index 0000000000..ee0ccc62d2
--- /dev/null
+++ b/tobago-example/tobago-example-demo/src/main/webapp/content/080-sheet/32-action/Sheet_Action.xhtml
@@ -0,0 +1,39 @@
+<?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:tc="http://myfaces.apache.org/tobago/component"
+ xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
+ xmlns:f="http://xmlns.jcp.org/jsf/core">
+
+ <tc:section label="Action in a sheet">
+
+ <tc:sheet id="sheet" value="#{sheetController.solarList}" var="object" markup="small">
+ <tc:column label="Name">
+ <tc:out value="#{object.name}" id="name" labelLayout="skip"/>
+ </tc:column>
+ <tc:column label="Action">
+ <tc:link action="#{sheetActionController.deleteAction(object)}"
+ image="bi-trash" id="action" labelLayout="skip"/>
+ </tc:column>
+ </tc:sheet>
+
+ </tc:section>
+</ui:composition>