org.apache.myfaces.trinidad.component.UIXComponentRef Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of trinidad-api Show documentation
Show all versions of trinidad-api Show documentation
Public API for the Apache MyFaces Trinidad project
The newest version!
// WARNING: This file was automatically generated. Do not edit it directly,
// or you will lose your changes.
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.myfaces.trinidad.component;
import java.io.IOException;
import java.util.AbstractMap;
import java.util.Collections;
import java.util.Map;
import java.util.Set;
import javax.faces.FacesException;
import javax.faces.component.ContextCallback;
import javax.faces.component.NamingContainer;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.event.AbortProcessingException;
import javax.faces.event.FacesEvent;
import org.apache.myfaces.trinidad.bean.FacesBean;
import org.apache.myfaces.trinidad.bean.PropertyKey;
import org.apache.myfaces.trinidad.logging.TrinidadLogger;
import org.apache.myfaces.trinidad.util.ComponentUtils;
/**
*
* This component inserts a component (defined by a separate page
* that starts with <tr:componentDef>)
* into the current page. The "id" attribute is required on this
* component, which implements NamingContainer. This component may have
* a value, custom attributes, or both. The value will be
* made available to within component definition using the "binding"
* EL attribute. Custom attributes, defined with
* <f:attribute> or <tr:attribute>, will also
* be made available within the component definition - see the
* <tr:componentDef> tag documentation for more information.
*
* This component may also have facets. Each facet may be referenced
* exactly once from within a <tr:componentDef> tag by
* using a <tr:facetRef> - see the
* <tr:componentRef> tag documentation for more information.
*
* Events:
*
*
* Type
* Phases
* Description
*
*
* org.apache.myfaces.trinidad.event.AttributeChangeEvent
* Invoke
Application
Apply
Request
Values
* Event delivered to describe an attribute change. Attribute change events are not delivered for any programmatic change to a property. They are only delivered when a renderer changes a property without the application's specific request. An example of an attribute change event might include the width of a column that supported client-side resizing.
*
*
*/
public class UIXComponentRef extends UIXComponentBase
implements NamingContainer
{
static public final FacesBean.Type TYPE = new FacesBean.Type(
UIXComponentBase.TYPE);
static public final PropertyKey VALUE_KEY =
TYPE.registerKey("value");
static public final PropertyKey COMPONENT_TYPE_KEY =
TYPE.registerKey("componentType", String.class);
static public final PropertyKey VAR_KEY =
TYPE.registerKey("var", String.class);
static public final String COMPONENT_FAMILY =
"org.apache.myfaces.trinidad.ComponentRef";
static public final String COMPONENT_TYPE =
"org.apache.myfaces.trinidad.ComponentRef";
/**
* Construct an instance of the UIXComponentRef.
*/
public UIXComponentRef()
{
super(null);
}
@Override
public boolean invokeOnComponent(FacesContext context,
String clientId,
ContextCallback callback)
throws FacesException
{
// optimize case where clientId isn't in NamingContainer
return invokeOnNamingContainerComponent(context, clientId, callback);
}
@Override
public void queueEvent(FacesEvent event)
{
// we want to wrap up
// the event so we can execute it in the correct context (with the correct
// pageDefinition):
event = new WrapperEvent(this, event);
super.queueEvent(event);
}
@Override
public void broadcast(FacesEvent event)
throws AbortProcessingException
{
if (event instanceof WrapperEvent)
{
final WrapperEvent wrapper = (WrapperEvent) event;
final FacesContext context = FacesContext.getCurrentInstance();
Runnable runner = new Runnable()
{
public void run()
{
wrapper.broadcastWrappedEvent(context);
}
};
_processPhase(context, runner);
}
else
{
super.broadcast(event);
}
}
@Override
public void processDecodes(final FacesContext context)
{
Runnable runner = new Runnable()
{
public void run()
{
UIXComponentRef.super.processDecodes(context);
}
};
_processPhase(context, runner);
}
@Override
public void processValidators(final FacesContext context)
{
Runnable runner = new Runnable()
{
public void run()
{
UIXComponentRef.super.processValidators(context);
}
};
_processPhase(context, runner);
}
@Override
public void processUpdates(final FacesContext context)
{
Runnable runner = new Runnable()
{
public void run()
{
UIXComponentRef.super.processUpdates(context);
}
};
_processPhase(context, runner);
}
@Override
public void encodeBegin(FacesContext context) throws IOException
{
_setupEL(context);
super.encodeBegin(context);
}
@Override
public void encodeEnd(final FacesContext context) throws IOException
{
super.encodeEnd(context);
_resetEL(context);
}
private void _setupEL(FacesContext context)
{
UIXComponentRef region = _getParent();
// in the JSP VE we try to display a regiondef page. so we can't
// blow up if there isn't a parent region component.
if (region != null)
{
Object newValue = region.getValue();
_oldValue =
TableUtils.setupELVariable(context, _BINDINGS_VAR, newValue);
String var = _getVar();
_oldVar =
TableUtils.setupELVariable(context, var, new AttrMap());
}
}
private void _resetEL(FacesContext context)
{
TableUtils.setupELVariable(context, _BINDINGS_VAR, _oldValue);
String var = _getVar();
TableUtils.setupELVariable(context, var, _oldVar);
_oldValue = Boolean.FALSE; // GC
_oldVar = null; // GC
}
private void _processPhase(FacesContext context, Runnable runner)
{
assert context != null : "FacesContext is null";
if (!isRendered())
return;
_setupEL(context);
try
{
runner.run();
}
finally
{
_resetEL(context);
}
}
private UIXComponentRef _getParent()
{
for(UIComponent test = this; test != null; test = test.getParent())
{
if (test instanceof UIXComponentRef)
return (UIXComponentRef) test;
}
_LOG.severe("NO_PARENT_COMPONENTREF_FOUND");
return null;
}
private String _getVar()
{
if (_var == null)
{
_var = getVar();
if (_var == null)
{
_LOG.fine("var not set");
_var = "null"; // initialize so that we don't keep checking.
}
}
return _var;
}
private final class AttrMap extends AbstractMap