Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright (c) 1997, 2020 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/
package com.sun.faces.facelets.component;
import static com.sun.faces.cdi.CdiUtils.createDataModel;
import static com.sun.faces.facelets.tag.faces.ComponentSupport.restoreFullDescendantComponentDeltaStates;
import static com.sun.faces.facelets.tag.faces.ComponentSupport.restoreFullDescendantComponentStates;
import static com.sun.faces.facelets.tag.faces.ComponentSupport.restoreTransientDescendantComponentStates;
import static com.sun.faces.facelets.tag.faces.ComponentSupport.saveDescendantComponentStates;
import static com.sun.faces.facelets.tag.faces.ComponentSupport.saveDescendantInitialComponentStates;
import static com.sun.faces.renderkit.RenderKitUtils.PredefinedPostbackParameter.BEHAVIOR_SOURCE_PARAM;
import static com.sun.faces.util.Util.isNestedInIterator;
import java.io.IOException;
import java.io.Serializable;
import java.sql.ResultSet;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import com.sun.faces.facelets.tag.IterationStatus;
import jakarta.el.ValueExpression;
import jakarta.faces.FacesException;
import jakarta.faces.application.Application;
import jakarta.faces.application.FacesMessage;
import jakarta.faces.application.StateManager;
import jakarta.faces.component.ContextCallback;
import jakarta.faces.component.EditableValueHolder;
import jakarta.faces.component.UIComponent;
import jakarta.faces.component.UIForm;
import jakarta.faces.component.UINamingContainer;
import jakarta.faces.component.visit.VisitCallback;
import jakarta.faces.component.visit.VisitContext;
import jakarta.faces.component.visit.VisitHint;
import jakarta.faces.component.visit.VisitResult;
import jakarta.faces.context.FacesContext;
import jakarta.faces.event.AbortProcessingException;
import jakarta.faces.event.FacesEvent;
import jakarta.faces.event.FacesListener;
import jakarta.faces.event.PhaseId;
import jakarta.faces.event.PostValidateEvent;
import jakarta.faces.event.PreValidateEvent;
import jakarta.faces.model.ArrayDataModel;
import jakarta.faces.model.DataModel;
import jakarta.faces.model.IterableDataModel;
import jakarta.faces.model.ListDataModel;
import jakarta.faces.model.ResultSetDataModel;
import jakarta.faces.model.ScalarDataModel;
import jakarta.faces.render.Renderer;
public class UIRepeat extends UINamingContainer {
public static final String COMPONENT_TYPE = "facelets.ui.Repeat";
public static final String COMPONENT_FAMILY = "facelets";
private final static DataModel EMPTY_MODEL = new ListDataModel<>(Collections.emptyList());
// our data
private Object value;
private transient DataModel model;
// variables
private String var;
private String varStatus;
private int index = -1;
private Integer originalBegin;
private Integer originalEnd;
private Integer begin;
private Integer end;
private Integer step;
private Integer size;
private Boolean rowStatePreserved;
private Object initialDescendantFullComponentState = null;
private Map preservedRowStates = new HashMap<>();
private Map transientRowStates = new HashMap<>();
public UIRepeat() {
setRendererType("facelets.ui.Repeat");
}
@Override
public String getFamily() {
return COMPONENT_FAMILY;
}
public void setEnd(Integer end) {
this.end = end;
}
public Integer getEnd() {
if (end != null) {
return end;
}
ValueExpression ve = getValueExpression("end");
if (ve != null) {
return (Integer) ve.getValue(getFacesContext().getELContext());
}
return null;
}
public void setSize(Integer size) {
this.size = size;
}
public Integer getSize() {
if (size != null) {
return size;
}
ValueExpression ve = getValueExpression("size");
if (ve != null) {
return (Integer) ve.getValue(getFacesContext().getELContext());
}
return null;
}
public void setOffset(Integer offset) {
begin = offset;
}
public Integer getOffset() {
if (begin != null) {
return begin;
}
ValueExpression ve = getValueExpression("offset");
if (ve != null) {
return (Integer) ve.getValue(getFacesContext().getELContext());
}
return null;
}
public void setBegin(Integer begin) {
this.begin = begin;
}
public Integer getBegin() {
if (begin != null) {
return begin;
}
ValueExpression ve = getValueExpression("begin");
if (ve != null) {
return (Integer) ve.getValue(getFacesContext().getELContext());
}
return null;
}
public void setStep(Integer step) {
this.step = step;
}
public Integer getStep() {
if (step != null) {
return step;
}
ValueExpression ve = getValueExpression("step");
if (ve != null) {
return (Integer) ve.getValue(getFacesContext().getELContext());
}
return null;
}
/**
*
* Boolean flag directing how the per-row component state of {@link EditableValueHolder} children should be handled across requests on the same view.
* If set to {@code true}, then state for {@link EditableValueHolder} components in each row will not be discarded before a new row is rendered.
* If not specified, the default value is {@code false}.
*
*
* This attribute should be set only when the current repeat component contains {@link UIForm} children which in turn contains {@link EditableValueHolder} children.
* This will only work reliably when the data model of the current repeat component does not change across requests on the same view by e.g. sorting, adding or removing rows.
* The alternative is to use c:forEach instead.
*
*
* @param rowStatePreserved Whether to preserve row state while rendering
* @since 4.1
*/
public void setRowStatePreserved(boolean rowStatePreserved) {
this.rowStatePreserved = rowStatePreserved;
}
/**
*
* Returns whether row state is preserved as per {@link #setRowStatePreserved(boolean)}.
*
*
* @return Whether row state is preserved.
* @since 4.1
*/
public boolean isRowStatePreserved() {
if (rowStatePreserved != null) {
return rowStatePreserved;
}
ValueExpression ve = getValueExpression("rowStatePreserved");
if (ve != null) {
return (Boolean) ve.getValue(getFacesContext().getELContext());
}
return false;
}
public String getVar() {
return var;
}
public void setVar(String var) {
this.var = var;
}
public String getVarStatus() {
return varStatus;
}
public void setVarStatus(String varStatus) {
this.varStatus = varStatus;
}
private void resetDataModel(FacesContext context) {
if (isNestedInIterator(context, this)) {
this.setDataModel(null);
}
}
private void setDataModel(DataModel model) {
// noinspection unchecked
this.model = model;
}
private DataModel getDataModel() {
if (model == null) {
Object val = getValue();
if (val == null) {
if (originalBegin == null) {
originalBegin = getBegin();
}
if (originalEnd == null) {
originalEnd = getEnd();
}
Integer begin = originalBegin;
Integer end = originalEnd;
if (end == null) {
if (begin == null) {
model = EMPTY_MODEL;
} else {
throw new IllegalArgumentException("end");
}
} else {
int b = begin == null ? 0 : begin;
int e = end;
int d = b < e ? 1 : b > e ? -1 : 0;
int s = Math.abs(e - b) + 1;
Integer[] array = new Integer[s];
for (int i = 0; i < s; i++) {
array[i] = b + i * d;
}
model = new ArrayDataModel<>(array);
setBegin(0);
setEnd(s);
}
} else if (val instanceof DataModel) {
// noinspection unchecked
model = (DataModel