use of jakarta.faces.view.facelets.TextHandler in project myfaces by apache.
the class CompositeComponentResourceTagHandler method applyNextHandlerIfNotApplied.
@SuppressWarnings("unchecked")
protected void applyNextHandlerIfNotApplied(FaceletContext ctx, UIComponent c) throws IOException {
// Apply all facelets not applied yet.
CompositeComponentBeanInfo beanInfo = (CompositeComponentBeanInfo) c.getAttributes().get(UIComponent.BEANINFO_KEY);
BeanDescriptor beanDescriptor = beanInfo.getBeanDescriptor();
boolean insertChildrenUsed = (beanDescriptor.getValue(InsertChildrenHandler.INSERT_CHILDREN_USED) != null);
List<String> insertFacetList = (List<String>) beanDescriptor.getValue(InsertFacetHandler.INSERT_FACET_USED);
if (nextHandler instanceof jakarta.faces.view.facelets.CompositeFaceletHandler) {
for (FaceletHandler handler : ((jakarta.faces.view.facelets.CompositeFaceletHandler) nextHandler).getHandlers()) {
if (handler instanceof jakarta.faces.view.facelets.FacetHandler) {
if (insertFacetList == null || !insertFacetList.contains(((jakarta.faces.view.facelets.FacetHandler) handler).getFacetName(ctx))) {
handler.apply(ctx, c);
}
} else if (handler instanceof InsertFacetHandler) {
if (insertFacetList == null || !insertFacetList.contains(((InsertFacetHandler) handler).getFacetName(ctx))) {
handler.apply(ctx, c);
}
} else if (insertChildrenUsed) {
if (!(handler instanceof jakarta.faces.view.facelets.ComponentHandler || handler instanceof ComponentContainerHandler || handler instanceof TextHandler)) {
handler.apply(ctx, c);
}
} else {
handler.apply(ctx, c);
}
}
} else {
if (nextHandler instanceof jakarta.faces.view.facelets.FacetHandler) {
if (insertFacetList == null || !insertFacetList.contains(((jakarta.faces.view.facelets.FacetHandler) nextHandler).getFacetName(ctx))) {
nextHandler.apply(ctx, c);
}
} else if (nextHandler instanceof InsertFacetHandler) {
if (insertFacetList == null || !insertFacetList.contains(((InsertFacetHandler) nextHandler).getFacetName(ctx))) {
nextHandler.apply(ctx, c);
}
} else if (insertChildrenUsed) {
if (!(nextHandler instanceof jakarta.faces.view.facelets.ComponentHandler || nextHandler instanceof ComponentContainerHandler || nextHandler instanceof TextHandler)) {
nextHandler.apply(ctx, c);
}
} else {
nextHandler.apply(ctx, c);
}
}
// Check for required facets
Map<String, PropertyDescriptor> facetPropertyDescriptorMap = (Map<String, PropertyDescriptor>) beanDescriptor.getValue(UIComponent.FACETS_KEY);
if (facetPropertyDescriptorMap != null) {
List<String> facetsRequiredNotFound = null;
for (Map.Entry<String, PropertyDescriptor> entry : facetPropertyDescriptorMap.entrySet()) {
ValueExpression requiredExpr = (ValueExpression) entry.getValue().getValue("required");
if (requiredExpr != null) {
Boolean required = (Boolean) requiredExpr.getValue(ctx.getFacesContext().getELContext());
if (Boolean.TRUE.equals(required)) {
initFacetHandlersMap(ctx);
if (!_facetHandlersMap.containsKey(entry.getKey())) {
if (facetsRequiredNotFound == null) {
facetsRequiredNotFound = new ArrayList(facetPropertyDescriptorMap.size());
}
facetsRequiredNotFound.add(entry.getKey());
}
}
}
}
if (facetsRequiredNotFound != null && !facetsRequiredNotFound.isEmpty()) {
throw new TagException(getTag(), "The following facets are required by the component: " + facetsRequiredNotFound);
}
}
}
use of jakarta.faces.view.facelets.TextHandler in project mojarra by eclipse-ee4j.
the class SetHandler method apply.
@Override
public void apply(FaceletContext ctx, UIComponent parent) throws IOException {
StringBuilder bodyValue = new StringBuilder();
Iterator iter = TagHandlerImpl.findNextByType(nextHandler, TextHandler.class);
while (iter.hasNext()) {
TextHandler text = (TextHandler) iter.next();
bodyValue.append(text.getText(ctx));
}
// true if either a value in body or value attr
boolean valSet = bodyValue.length() > 0 || value != null && value.getValue().length() > 0;
// Apply precedence algorithm for attributes. The JstlCoreTLV doesn't
// seem to enforce much in the way of this, so I edburns needs to check
// with an authority on the matter, probabyl Kin-Man Chung
ValueExpression veObj;
ValueExpression lhs;
String expr;
if (value != null) {
veObj = value.getValueExpression(ctx, Object.class);
} else {
veObj = ctx.getExpressionFactory().createValueExpression(ctx.getFacesContext().getELContext(), bodyValue.toString(), Object.class);
}
// Otherwise, if var is set, ignore the other attributes
if (var != null) {
String scopeStr, varStr = var.getValue(ctx);
// If scope is set, check for validity
if (null != scope) {
if (0 == scope.getValue().length()) {
throw new TagException(tag, "zero length scope attribute set");
}
if (scope.isLiteral()) {
scopeStr = scope.getValue();
} else {
scopeStr = scope.getValue(ctx);
}
if (scopeStr.equals("page")) {
throw new TagException(tag, "page scope does not exist in Faces, consider using view scope instead.");
}
if (scopeStr.equals("request") || scopeStr.equals("session") || scopeStr.equals("application") || scopeStr.equals("view")) {
scopeStr = scopeStr + "Scope";
}
// otherwise, assume it's a valid scope. With custom scopes,
// it may be.
// Conjure up an expression
expr = "#{" + scopeStr + "." + varStr + "}";
lhs = ctx.getExpressionFactory().createValueExpression(ctx, expr, Object.class);
lhs.setValue(ctx, veObj.getValue(ctx));
} else {
ctx.getVariableMapper().setVariable(varStr, veObj);
}
} else {
// Otherwise, target, property and value must be set
if (null == target || null == target.getValue() || target.getValue().length() <= 0 || null == property || null == property.getValue() || property.getValue().length() <= 0 || !valSet) {
throw new TagException(tag, "when using this tag either one of var and value, or (target, property, value) must be set.");
}
// Ensure that target is an expression
if (target.isLiteral()) {
throw new TagException(tag, "value of target attribute must be an expression");
}
// Get the value of property
String propertyStr = null;
if (property.isLiteral()) {
propertyStr = property.getValue();
} else {
propertyStr = property.getValue(ctx);
}
ValueExpression targetVe = target.getValueExpression(ctx, Object.class);
Object targetValue = targetVe.getValue(ctx);
ctx.getFacesContext().getELContext().getELResolver().setValue(ctx, targetValue, propertyStr, veObj.getValue(ctx));
}
}
Aggregations