use of jakarta.faces.component.visit.VisitResult in project myfaces by apache.
the class IdSearchKeywordResolver method resolve.
@Override
public void resolve(SearchKeywordContext expressionContext, UIComponent current, String keyword) {
FacesContext facesContext = expressionContext.getSearchExpressionContext().getFacesContext();
final String targetId = extractId(keyword);
if (expressionContext.getSearchExpressionContext().getExpressionHints() != null && expressionContext.getSearchExpressionContext().getExpressionHints().contains(SearchExpressionHint.SKIP_VIRTUAL_COMPONENTS)) {
// Avoid visit tree because in this case we need real component instances.
// This means components inside UIData will not be scanned.
withId(facesContext, targetId, current, expressionContext.getCallback());
expressionContext.setKeywordResolved(true);
} else {
current.visitTree(VisitContext.createVisitContext(facesContext, null, expressionContext.getSearchExpressionContext().getVisitHints()), new VisitCallback() {
@Override
public VisitResult visit(VisitContext context, UIComponent target) {
if (targetId.equals(target.getId())) {
expressionContext.invokeContextCallback(target);
if (expressionContext.getSearchExpressionContext().getExpressionHints() != null && expressionContext.getSearchExpressionContext().getExpressionHints().contains(SearchExpressionHint.RESOLVE_SINGLE_COMPONENT)) {
return VisitResult.COMPLETE;
}
return VisitResult.ACCEPT;
} else {
return VisitResult.ACCEPT;
}
}
});
}
}
use of jakarta.faces.component.visit.VisitResult in project myfaces by apache.
the class UIComponent method visitTree.
/**
* The visit tree method, visit tree walks over a subtree and processes
* the callback object to perform some operation on the subtree
* <p>
* there are some details in the implementation which according to the spec have
* to be in place:
* a) before calling the callback and traversing into the subtree pushComponentToEL
* has to be called
* b) after the processing popComponentFromEL has to be performed to remove the component
* from the el
* </p>
* <p>
* The tree traversal optimizations are located in the visit context and can be replaced
* via the VisitContextFactory in the faces-config factory section
* </p>
*
* @param context the visit context which handles the processing details
* @param callback the callback to be performed
* @return false if the processing is not done true if we can shortcut
* the visiting because we are done with everything
*
* @since 2.0
*/
public boolean visitTree(VisitContext context, VisitCallback callback) {
try {
pushComponentToEL(context.getFacesContext(), this);
if (!isVisitable(context)) {
return false;
}
VisitResult res = context.invokeVisitCallback(this, callback);
switch(res) {
// we are done nothing has to be processed anymore
case COMPLETE:
return true;
case REJECT:
return false;
// accept
default:
if (getFacetCount() > 0) {
for (UIComponent facet : getFacets().values()) {
if (facet.visitTree(context, callback)) {
return true;
}
}
}
int childCount = getChildCount();
if (childCount > 0) {
for (int i = 0; i < childCount; i++) {
UIComponent child = getChildren().get(i);
if (child.visitTree(context, callback)) {
return true;
}
}
}
return false;
}
} finally {
// all components must call popComponentFromEl after visiting is finished
popComponentFromEL(context.getFacesContext());
}
}
use of jakarta.faces.component.visit.VisitResult in project myfaces by apache.
the class UIData method visitTree.
/**
* Overrides the behavior in
* UIComponent.visitTree(jakarta.faces.component.visit.VisitContext, jakarta.faces.component.visit.VisitCallback)
* to handle iteration correctly.
*
* @param context the visit context which handles the processing details
* @param callback the callback to be performed
* @return false if the processing is not done true if we can shortcut
* the visiting because we are done with everything
*
* @since 2.0
*/
@Override
public boolean visitTree(VisitContext context, VisitCallback callback) {
boolean skipIterationHint = context.getHints().contains(VisitHint.SKIP_ITERATION);
if (skipIterationHint) {
return super.visitTree(context, callback);
}
// push the Component to EL
pushComponentToEL(context.getFacesContext(), this);
try {
if (!isVisitable(context)) {
return false;
}
boolean isCachedFacesContext = isCachedFacesContext();
if (!isCachedFacesContext) {
setCachedFacesContext(context.getFacesContext());
}
// save the current row index
int oldRowIndex = getRowIndex();
// set row index to -1 to process the facets and to get the rowless clientId
setRowIndex(-1);
try {
VisitResult visitResult = context.invokeVisitCallback(this, callback);
switch(visitResult) {
case COMPLETE:
// we are done nothing has to be processed anymore
return true;
case REJECT:
return false;
default:
// accept; determine if we need to visit our children
Collection<String> subtreeIdsToVisit = context.getSubtreeIdsToVisit(this);
boolean doVisitChildren = subtreeIdsToVisit != null && !subtreeIdsToVisit.isEmpty();
if (doVisitChildren) {
// visit the facets of the component
if (getFacetCount() > 0) {
for (UIComponent facet : getFacets().values()) {
if (facet.visitTree(context, callback)) {
return true;
}
}
}
if (skipIterationHint) {
// If SKIP_ITERATION is enabled, do not take into account rows.
for (int i = 0, childCount = getChildCount(); i < childCount; i++) {
UIComponent child = getChildren().get(i);
if (child.visitTree(context, callback)) {
return true;
}
}
} else {
// every row) and also visit the column's facets
for (int i = 0, childCount = getChildCount(); i < childCount; i++) {
UIComponent child = getChildren().get(i);
if (child instanceof UIColumn) {
VisitResult columnResult = context.invokeVisitCallback(child, callback);
if (columnResult == VisitResult.COMPLETE) {
return true;
}
if (child.getFacetCount() > 0) {
for (UIComponent facet : child.getFacets().values()) {
if (facet.visitTree(context, callback)) {
return true;
}
}
}
}
}
// iterate over the rows
int rowsToProcess = getRows();
// if getRows() returns 0, all rows have to be processed
if (rowsToProcess == 0) {
rowsToProcess = getRowCount();
}
int rowIndex = getFirst();
for (int rowsProcessed = 0; rowsProcessed < rowsToProcess; rowsProcessed++, rowIndex++) {
setRowIndex(rowIndex);
if (!isRowAvailable()) {
return false;
}
// visit the children of every child of the UIData that is an instance of UIColumn
for (int i = 0, childCount = getChildCount(); i < childCount; i++) {
UIComponent child = getChildren().get(i);
if (child instanceof UIColumn) {
for (int j = 0, grandChildCount = child.getChildCount(); j < grandChildCount; j++) {
UIComponent grandchild = child.getChildren().get(j);
if (grandchild.visitTree(context, callback)) {
return true;
}
}
}
}
}
}
}
}
} finally {
// restore the old row index
setRowIndex(oldRowIndex);
if (!isCachedFacesContext) {
setCachedFacesContext(null);
}
}
} finally {
// pop the component from EL
popComponentFromEL(context.getFacesContext());
}
// Return false to allow the visiting to continue
return false;
}
use of jakarta.faces.component.visit.VisitResult in project myfaces by apache.
the class UIForm method visitTree.
@Override
public boolean visitTree(VisitContext context, VisitCallback callback) {
if (!isPrependId()) {
// and prevent visit child nodes. Just do it as default.
return super.visitTree(context, callback);
} else {
pushComponentToEL(context.getFacesContext(), this);
boolean isCachedFacesContext = isCachedFacesContext();
try {
if (!isCachedFacesContext) {
setCachedFacesContext(context.getFacesContext());
}
if (!isVisitable(context)) {
return false;
}
VisitResult res = context.invokeVisitCallback(this, callback);
switch(res) {
// we are done nothing has to be processed anymore
case COMPLETE:
return true;
case REJECT:
return false;
// accept
default:
// Take advantage of the fact this is a NamingContainer
// and we can know if there are ids to visit inside it
Collection<String> subtreeIdsToVisit = context.getSubtreeIdsToVisit(this);
if (subtreeIdsToVisit != null && !subtreeIdsToVisit.isEmpty()) {
if (getFacetCount() > 0) {
for (UIComponent facet : getFacets().values()) {
if (facet.visitTree(context, callback)) {
return true;
}
}
}
for (int i = 0, childCount = getChildCount(); i < childCount; i++) {
UIComponent child = getChildren().get(i);
if (child.visitTree(context, callback)) {
return true;
}
}
}
return false;
}
} finally {
// all components must call popComponentFromEl after visiting is finished
popComponentFromEL(context.getFacesContext());
if (!isCachedFacesContext) {
setCachedFacesContext(null);
}
}
}
}
use of jakarta.faces.component.visit.VisitResult in project myfaces by apache.
the class UISelectOne method processValidators.
/**
* Verify that when ever there is a ValueExpression and submitted value is not empty, then
* visit all the UISelectItem elements within the UISelectOne radio components to check if
* the submitted value exists in any of the select items.
*
* @see jakarta.faces.component.UIInput#processValidators(jakarta.faces.context.FacesContext)
*/
@Override
public void processValidators(FacesContext context) {
String group = getGroup();
ValueExpression ve = getValueExpression("value");
String submittedValue = (String) getSubmittedValue();
if (group != null && !group.isEmpty() && ve != null && !isEmpty(submittedValue)) {
final UIComponent form = getRadioNestingForm(context, this);
form.visitTree(VisitContext.createVisitContext(context), new VisitCallback() {
@Override
public VisitResult visit(VisitContext visitContext, UIComponent target) {
if (target instanceof UISelectOne && ((UISelectOne) target).getGroup().equals(group)) {
UISelectOne radio = (UISelectOne) target;
// and verify if the submitted value exists
for (Iterator<UIComponent> iter = radio.getChildren().iterator(); iter.hasNext(); ) {
UIComponent component = iter.next();
if (component instanceof UISelectItem) {
UISelectItem item = (UISelectItem) component;
if (item.getItemValue().equals(submittedValue)) {
selectItemValueFound = true;
return VisitResult.COMPLETE;
}
}
}
return VisitResult.REJECT;
}
return VisitResult.ACCEPT;
}
});
}
super.processValidators(context);
}
Aggregations