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 #5473: Utilize ability to pass VisitHints to UIViewRoot#resetValues() #5474

Merged
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 @@ -72,8 +72,6 @@ public class PartialViewContextImpl extends PartialViewContext {
// Log instance for this class
private static final Logger LOGGER = FacesLogger.CONTEXT.getLogger();

private static final Set<VisitHint> SKIP_UNRENDERED_HINT = EnumSet.of(SKIP_UNRENDERED);

private static final Set<VisitHint> SKIP_UNRENDERED_AND_EXECUTE_LIFECYCLE_HINTS = EnumSet.of(SKIP_UNRENDERED, EXECUTE_LIFECYCLE);


Expand Down Expand Up @@ -293,7 +291,7 @@ public void processPartial(PhaseId phaseId) {
writer.startDocument();

if (isResetValues()) {
resetValues(viewRoot, myRenderIds, ctx);
viewRoot.resetValues(ctx, myRenderIds, SKIP_UNRENDERED);
}

if (isRenderAll()) {
Expand Down Expand Up @@ -389,7 +387,8 @@ private void processComponents(UIComponent component, PhaseId phaseId, Collectio
// process. Create our (partial) VisitContext and the
// VisitCallback that will be invoked for each component that
// is visited.
VisitContext visitContext = createPartialVisitContext(context, phaseClientIds, true);
VisitContextFactory visitContextFactory = (VisitContextFactory) FactoryFinder.getFactory(VISIT_CONTEXT_FACTORY);
VisitContext visitContext = visitContextFactory.getVisitContext(context, phaseClientIds, SKIP_UNRENDERED_AND_EXECUTE_LIFECYCLE_HINTS);
PhaseAwareVisitCallback visitCallback = new PhaseAwareVisitCallback(ctx, phaseId);
component.visitTree(visitContext, visitCallback);

Expand All @@ -406,34 +405,6 @@ private void processComponents(UIComponent component, PhaseId phaseId, Collectio
}
}

private static VisitContext createPartialVisitContext(FacesContext context, Collection<String> clientIds, boolean executeLifecycle) {

// Note that we use the SKIP_UNRENDERED hint as
// we only want to visit the rendered subtree.
Set<VisitHint> hints = executeLifecycle ? SKIP_UNRENDERED_AND_EXECUTE_LIFECYCLE_HINTS : SKIP_UNRENDERED_HINT;
VisitContextFactory visitContextFactory = (VisitContextFactory) FactoryFinder.getFactory(VISIT_CONTEXT_FACTORY);
return visitContextFactory.getVisitContext(context, clientIds, hints);
}

private static void resetValues(UIComponent component, Collection<String> clientIds, FacesContext context) {

// NOTE: this is indeed a copy of the one in UIViewRoot#resetValues().
// The difference is that we want to be able to control the visit hints.
// This isn't possible via the UIViewRoot#resetValues() API in its current form.
component.visitTree(createPartialVisitContext(context, clientIds, false), new DoResetValues());
}

private static class DoResetValues implements VisitCallback {

@Override
public VisitResult visit(VisitContext context, UIComponent target) {
if (target instanceof EditableValueHolder) {
((EditableValueHolder) target).resetValue();
}
return VisitResult.ACCEPT;
}
}

/**
* Unwraps {@link PartialVisitContext} from a chain of {@link VisitContextWrapper}s.
*
Expand Down
Loading