javax.faces.component.visit.VisitContext Java Examples

The following examples show how to use javax.faces.component.visit.VisitContext. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ResetInputAjaxActionListener.java    From ctsms with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public VisitResult visit(VisitContext context, UIComponent target) {
	FacesContext facesContext = context.getFacesContext();
	Collection<String> executeIds = facesContext.getPartialViewContext().getExecuteIds();
	if (executeIds.contains(target.getClientId(facesContext))) {
		return VisitResult.REJECT;
	}
	if (target instanceof EditableValueHolder) {
		((EditableValueHolder) target).resetValue();
	} else if (context.getIdsToVisit() != VisitContext.ALL_IDS) {
		// Render ID didn't specifically point an EditableValueHolder. Visit all children as well.
		if (!SKIP_COMPONENTS.contains(target.getClass())) {
			try {
				target.visitTree(createVisitContext(facesContext, null, context.getHints()), VISIT_CALLBACK);
			} catch (Exception e) {
			}
		}
	}
	return VisitResult.ACCEPT;
}
 
Example #2
Source File: TabRepeat.java    From BootsFaces-OSP with Apache License 2.0 6 votes vote down vote up
private boolean doVisitChildren(VisitContext context) {

		// Just need to check whether there are any ids under this
		// subtree. Make sure row index is cleared out since
		// getSubtreeIdsToVisit() needs our row-less client id.
		//
		// We only need to position if row iteration is actually needed.
		//
		if (requiresRowIteration(context)) {
			setIndex(context.getFacesContext(), -1);
		}
		Collection<String> idsToVisit = context.getSubtreeIdsToVisit(this);
		assert (idsToVisit != null);

		// All ids or non-empty collection means we need to visit our children.
		return (!idsToVisit.isEmpty());

	}
 
Example #3
Source File: TabRepeat.java    From BootsFaces-OSP with Apache License 2.0 5 votes vote down vote up
private boolean requiresRowIteration(VisitContext ctx) {
	boolean shouldIterate = !ctx.getHints().contains(VisitHint.SKIP_ITERATION);
	if (!shouldIterate) {
		FacesContext faces = ctx.getFacesContext();
		String sourceId = faces.getExternalContext().getRequestParameterMap().get("javax.faces.source");
		boolean containsSource = sourceId != null
				? sourceId.startsWith(super.getClientId(faces) + getSeparatorChar(faces))
				: false;
		return containsSource;
	} else {
		return shouldIterate;
	}
}
 
Example #4
Source File: TabRepeat.java    From BootsFaces-OSP with Apache License 2.0 5 votes vote down vote up
private boolean visitChildren(VisitContext context, VisitCallback callback) {
	Integer begin = this.getBegin();
	Integer end = this.getEnd();
	Integer step = this.getStep();

	int rowCount = getDataModel().getRowCount();
	int i = ((begin != null) ? begin : 0);
	int e = ((end != null) ? end : rowCount);
	int s = ((step != null) ? step : 1);
	validateIterationControlValues(rowCount, i, e);
	FacesContext faces = context.getFacesContext();
	this.setIndex(faces, i);
	this.updateIterationStatus(faces, new IterationStatus(true, (i + s > e || rowCount == 1), i, begin, end, step));
	while (i < e && this.isIndexAvailable()) {

		this.setIndex(faces, i);
		this.updateIterationStatus(faces, new IterationStatus(false, i + s >= e, i, begin, end, step));
		for (UIComponent kid : getChildren()) {
			if (kid.visitTree(context, callback)) {
				return true;
			}
		}
		i += s;
	}

	return false;
}
 
Example #5
Source File: UISwitchFacet.java    From XPagesExtensionLibrary with Apache License 2.0 5 votes vote down vote up
@Override
  public boolean visitTree(VisitContext context, VisitCallback callback) {
if (!isVisitable(context)) {
	return false;
}
// Check for the current component
VisitResult res = context.invokeVisitCallback(this, callback);
if (res == VisitResult.COMPLETE) return true;
if (res == VisitResult.ACCEPT) {
	// we should visit the children if we have ids (all or selected) to visit
	boolean visitChildren = !context.getSubtreeIdsToVisit(this).isEmpty();
	if (visitChildren) {
		// visit the component facets
    	UIComponent facet = selectFacet(); 
    	if(facet!=null) {
    		try {
    			if(facet.visitTree(context, callback)) {
					return true;
        		}
    		} finally {
            	unselectFacet();
    		}
        }
	}
}
  	return false;
  }
 
Example #6
Source File: UIVarPublisherBase.java    From XPagesExtensionLibrary with Apache License 2.0 5 votes vote down vote up
@Override
public boolean visitTree(VisitContext context, VisitCallback callback) {
    try { 
        _shadowedData = publishControlData(context.getFacesContext());
        return super.visitTree(context, callback);
    } finally {
        revokeControlData(_shadowedData, context.getFacesContext());
        _shadowedData = null;
    }
}
 
Example #7
Source File: PhaseListenerBean.java    From tutorials with MIT License 5 votes vote down vote up
private void processComponentTree(UIComponent component, PhaseEvent event, boolean show) {
    component.visitTree(VisitContext.createVisitContext(event.getFacesContext()),
            (context, target) -> {
                if (target.getId() != null
                        && target.getId().startsWith("new-feature-")
                        && !show) {
                    target.setRendered(false);
                }
                return VisitResult.ACCEPT;
            });
}
 
Example #8
Source File: TabRepeat.java    From BootsFaces-OSP with Apache License 2.0 4 votes vote down vote up
@Override
public boolean visitTree(VisitContext context, VisitCallback callback) {

	if (this.getVar() == null) {
		return super.visitTree(context, callback);
	}

	// First check to see whether we are visitable. If not
	// short-circuit out of this subtree, though allow the
	// visit to proceed through to other subtrees.
	if (!isVisitable(context)) {
		return false;
	}

	FacesContext facesContext = context.getFacesContext();
	boolean visitRows = requiresRowIteration(context);

	int oldRowIndex = -1;
	if (visitRows) {
		oldRowIndex = getDataModel().getRowIndex();
		setIndex(facesContext, -1);
	}

	this.setDataModel(null);

	// Push ourselves to EL
	pushComponentToEL(facesContext, null);

	try {

		// Visit ourselves. Note that we delegate to the
		// VisitContext to actually perform the visit.
		VisitResult result = context.invokeVisitCallback(this, callback);

		// If the visit is complete, short-circuit out and end the visit
		if (result == VisitResult.COMPLETE) {
			return true;
		}

		// Visit children, short-circuiting as necessary
		if ((result == VisitResult.ACCEPT) && doVisitChildren(context)) {

			// And finally, visit rows
			if (!visitRows) {
				// visit rows without model access
				for (UIComponent kid : getChildren()) {
					if (kid.visitTree(context, callback)) {
						return true;
					}
				}
			} else {
				if (visitChildren(context, callback)) {
					return true;
				}
			}
		}
	} finally {
		// Clean up - pop EL and restore old row index
		popComponentFromEL(facesContext);
		if (visitRows) {
			setIndex(facesContext, oldRowIndex);
		}
	}

	// Return false to allow the visit to continue
	return false;
}