Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #5445 Dynamic actions not correctly processed #5446

Merged
merged 2 commits into from
May 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1685,11 +1685,21 @@ public void flush() {
* @param context the Faces context.
* @param clientId the client id of the component to find.
*/
private UIComponent locateComponentByClientId(final FacesContext context, final UIComponent parent, final String clientId) {
private UIComponent locateComponentByClientId(final FacesContext context, final UIComponent parent, final String clientId, final boolean dynamic) {
final List<UIComponent> found = new ArrayList<>(1);
UIComponent result = null;

parent.invokeOnComponent(context, clientId, (context1, target) -> found.add(target));
try {
parent.invokeOnComponent(context, clientId, (context1, target) -> found.add(target));
} catch (FacesException e) {
if (dynamic) {
LOGGER.log(FINE, e, () -> "Cannot find dynamic component " + clientId + " in " + parent.getClientId(context)
+ "; assuming it just doesn't exist anymore"
+ "; it will most likely emit a 'WARNING: Unable to save dynamic action' log later on anyway");
} else {
throw e;
}
}

/*
* Since we did not find it the cheaper way we need to assume there is a UINamingContainer that does not prepend its ID.
Expand Down Expand Up @@ -1744,11 +1754,11 @@ private void reapplyDynamicActions(FacesContext context) {
* @param struct the component struct.
*/
private void reapplyDynamicAdd(FacesContext context, ComponentStruct struct) {
UIComponent parent = locateComponentByClientId(context, context.getViewRoot(), struct.getParentClientId());
UIComponent parent = locateComponentByClientId(context, context.getViewRoot(), struct.getParentClientId(), false);

if (parent != null) {

UIComponent child = locateComponentByClientId(context, parent, struct.getClientId());
UIComponent child = locateComponentByClientId(context, parent, struct.getClientId(), true);
StateContext stateContext = StateContext.getStateContext(context);

if (child == null) {
Expand Down Expand Up @@ -1786,7 +1796,7 @@ private void reapplyDynamicAdd(FacesContext context, ComponentStruct struct) {
* @param struct the component struct.
*/
private void reapplyDynamicRemove(FacesContext context, ComponentStruct struct) {
UIComponent child = locateComponentByClientId(context, context.getViewRoot(), struct.getClientId());
UIComponent child = locateComponentByClientId(context, context.getViewRoot(), struct.getClientId(), true);
if (child != null) {
StateContext stateContext = StateContext.getStateContext(context);
stateContext.getDynamicComponents().put(struct.getClientId(), child);
Expand Down
20 changes: 6 additions & 14 deletions impl/src/main/java/jakarta/faces/component/UIData.java
Original file line number Diff line number Diff line change
Expand Up @@ -899,9 +899,14 @@ public boolean invokeOnComponent(FacesContext context, String clientId, ContextC
}
}

// check column level facets, if any
// Check if we are looking for a component that is part of the actual skeleton.
if (getChildCount() > 0) {
for (UIComponent column : getChildren()) {
if (column.invokeOnComponent(context, clientId, callback)) {
return true;
}

// check column level facets, if any
if (column instanceof UIColumn) {
if (column.getFacetCount() > 0) {
for (UIComponent facet : column.getFacets().values()) {
Expand All @@ -914,19 +919,6 @@ public boolean invokeOnComponent(FacesContext context, String clientId, ContextC
}
}

/*
* Check if we are looking for a component that is part of the actual skeleton.
*/
if (getChildCount() > 0) {
for (UIComponent column : getChildren()) {
if (column instanceof UIColumn) {
if (column.invokeOnComponent(context, clientId, callback)) {
return true;
}
}
}
}

int lastSep, newRow, savedRowIndex = getRowIndex();
char sepChar = UINamingContainer.getSeparatorChar(context);
// If we need to strip out the rowIndex from our id
Expand Down
Loading