public abstract class UIMetawidget
extends javax.faces.component.UIInput
Its default RendererType is table
.
If the entire Metawidget resolves directly to a single widget, Metawidget allows you to attach converters, facets and validators to the dynamically chosen component. Tags placed inside the Metawidget tag will be moved on to the generated component. For example:
<m:metawidget value="#{user.name}">
<f:validator validatorId="myValidator">
</m:metawidget>
Conceptually, UIMetawidget
should only extend UIComponentBase
. This is
because it is not:
UIInput
, though it may contain input widgets
UIOutput
, though it may contain output widgets
ValueHolder
, as it does not use a Converter
EditableValueHolder
, as it does not use a Validator
However by extending UIInput
, we enable this useful 'attach facets to a single
widget' capability.
Modifier and Type | Class and Description |
---|---|
protected class |
UIMetawidget.Pipeline |
Modifier and Type | Field and Description |
---|---|
static String |
COMPONENT_ATTRIBUTE_METADATA
Component-level attribute used to store metadata.
|
static String |
COMPONENT_ATTRIBUTE_NOT_RECREATABLE
Component-level attribute used to prevent recreation.
|
static String |
COMPONENT_ATTRIBUTE_SECTION_DECORATOR
Component-level attribute used to store metadata.
|
Constructor and Description |
---|
UIMetawidget() |
Modifier and Type | Method and Description |
---|---|
void |
addInspectionResultProcessor(InspectionResultProcessor<UIMetawidget> inspectionResultProcessor) |
void |
addWidgetProcessor(WidgetProcessor<javax.faces.component.UIComponent,UIMetawidget> widgetProcessor)
Exposed mainly for those using
UIComponent.setBinding . |
protected void |
buildWidgets()
Build widgets for the given value binding.
|
void |
copyParameters(UIMetawidget copyFrom)
As discussed in the
setParameter JavaDoc, clients should use this method to
copy parameters, rather than creating UIParameter components directly. |
void |
encodeBegin(javax.faces.context.FacesContext context) |
protected void |
endBuild() |
<T> T |
getClientProperty(Object key)
Storage area for WidgetProcessors, Layouts, and other stateless clients.
|
abstract String |
getComponentType()
Get the component type used to create this Metawidget.
|
protected abstract String |
getDefaultConfiguration() |
String |
getFamily() |
String |
getLabelString(Map<String,String> attributes)
Returns a label for the given set of attributes.
|
Layout<javax.faces.component.UIComponent,javax.faces.component.UIComponent,UIMetawidget> |
getLayout() |
String |
getLocalizedKey(String key) |
String |
getParameter(String name)
Gets the parameter with the given name.
|
WidgetBuilder<javax.faces.component.UIComponent,UIMetawidget> |
getWidgetBuilder()
Exposed mainly for those using
UIComponent.setBinding . |
<T> T |
getWidgetProcessor(Class<T> widgetProcessorClass) |
List<WidgetProcessor<javax.faces.component.UIComponent,UIMetawidget>> |
getWidgetProcessors() |
void |
initNestedMetawidget(UIMetawidget nestedMetawidget,
Map<String,String> attributes)
Useful for WidgetBuilders to setup nested Metawidgets (eg.
|
String |
inspect(Object toInspect,
String type,
String... names)
Useful for WidgetBuilders to perform nested inspections (eg.
|
boolean |
isReadOnly() |
boolean |
isRendered() |
protected void |
layoutWidget(javax.faces.component.UIComponent component,
String elementName,
Map<String,String> attributes) |
protected UIMetawidget.Pipeline |
newPipeline()
Instantiate the Pipeline used by this Metawidget.
|
void |
putClientProperty(Object key,
Object value)
Storage area for WidgetProcessors, Layouts, and other stateless clients.
|
protected void |
registerBuildWidgetsSupport()
Register the mechanism used to build widgets.
|
void |
removeInspectionResultProcessor(InspectionResultProcessor<UIMetawidget> inspectionResultProcessor) |
void |
removeWidgetProcessor(WidgetProcessor<javax.faces.component.UIComponent,UIMetawidget> widgetProcessor)
Exposed mainly for those using
UIComponent.setBinding . |
void |
restoreState(javax.faces.context.FacesContext context,
Object state) |
Object |
saveState(javax.faces.context.FacesContext context) |
void |
setBuildWidgetsOnAjaxRequest(boolean buildWidgetsOnAjaxRequest)
By default,
UIMetawidget does not rebuild widgets upon an AJAX request unless
the Metawidget's Id is explicitly included in the list of execute
Ids. |
void |
setConfig(String config) |
void |
setInspectFromParent(boolean inspectFromParent)
Instructs the Metawidget to inspect the value binding from the parent.
|
void |
setInspectionResultProcessors(InspectionResultProcessor<UIMetawidget>... inspectionResultProcessors) |
void |
setInspector(Inspector inspector) |
void |
setLayout(Layout<javax.faces.component.UIComponent,javax.faces.component.UIComponent,UIMetawidget> layout) |
void |
setParameter(String name,
Object value)
Sets the parameter with the given name to the given value.
|
void |
setReadOnly(boolean readOnly) |
void |
setRendererType(String rendererType)
Overridden to flag whether the rendererType has been set explicitly by the page.
|
void |
setWidgetBuilder(WidgetBuilder<javax.faces.component.UIComponent,UIMetawidget> widgetBuilder) |
void |
setWidgetProcessors(WidgetProcessor<javax.faces.component.UIComponent,UIMetawidget>... widgetProcessors) |
protected void |
startBuild()
Build child widgets.
|
addValidator, addValueChangeListener, clearInitialState, compareValues, decode, getConvertedValue, getConverterMessage, getRequiredMessage, getSubmittedValue, getValidator, getValidatorMessage, getValidators, getValueChangeListener, getValueChangeListeners, isEmpty, isImmediate, isLocalValueSet, isRequired, isValid, markInitialState, processDecodes, processUpdates, processValidators, removeValidator, removeValueChangeListener, resetValue, setConverterMessage, setImmediate, setLocalValueSet, setRequired, setRequiredMessage, setSubmittedValue, setValid, setValidator, setValidatorMessage, setValue, setValueChangeListener, updateModel, validate, validateValue
getConverter, getLocalValue, getValue, setConverter
addClientBehavior, addFacesListener, broadcast, encodeChildren, encodeEnd, findComponent, getAttributes, getChildCount, getChildren, getClientBehaviors, getClientId, getDefaultEventName, getEventNames, getFacesContext, getFacesListeners, getFacet, getFacetCount, getFacets, getFacetsAndChildren, getId, getListenersForEventClass, getParent, getRenderer, getRendererType, getRendersChildren, getValueBinding, invokeOnComponent, isTransient, processRestoreState, processSaveState, queueEvent, removeFacesListener, restoreAttachedState, saveAttachedState, setId, setParent, setRendered, setTransient, setValueBinding, subscribeToEvent, unsubscribeFromEvent
encodeAll, getClientId, getCompositeComponentParent, getContainerClientId, getCurrentComponent, getCurrentCompositeComponent, getNamingContainer, getResourceBundleMap, getStateHelper, getStateHelper, getTransientStateHelper, getTransientStateHelper, getValueExpression, initialStateMarked, isCompositeComponent, isInView, isVisitable, popComponentFromEL, processEvent, pushComponentToEL, restoreTransientState, saveTransientState, setInView, setValueExpression, visitTree
public static final String COMPONENT_ATTRIBUTE_METADATA
public static final String COMPONENT_ATTRIBUTE_NOT_RECREATABLE
By default, Metawidget destroys and recreates every component after
processUpdates
and before encodeBegin
. This allows components to
update to reflect changed state in underlying domain objects. For example, components may
change from being UIOutput
labels to UIInput
text boxes after the
user clicks Edit
.
Most components work well with this approach. Some, however, maintain internal state that
would get lost if the component was destroyed and recreated. For example, the ICEfaces
SelectInputDate
component keeps its popup state internally. If it is destroyed
and recreated, the popup never appears.
Such components can be marked with COMPONENT_ATTRIBUTE_NOT_RECREATABLE
to
prevent their destruction and recreation. Of course, this somewhat impacts their flexibility.
For example, a SelectInputDate
could not change its date format in response to
another component on the form.
COMPONENT_ATTRIBUTE_NOT_RECREATABLE
is also used to mark components that
override default component generation, such as a UIStub
used to suppress a
field.
This attribute must be used in conjunction with OverriddenWidgetBuilder
.
public static final String COMPONENT_ATTRIBUTE_SECTION_DECORATOR
public String getFamily()
getFamily
in class javax.faces.component.UIInput
public boolean isReadOnly()
public void setReadOnly(boolean readOnly)
public void setConfig(String config)
public void setInspector(Inspector inspector)
public String inspect(Object toInspect, String type, String... names)
public void addInspectionResultProcessor(InspectionResultProcessor<UIMetawidget> inspectionResultProcessor)
public void removeInspectionResultProcessor(InspectionResultProcessor<UIMetawidget> inspectionResultProcessor)
public void setInspectionResultProcessors(InspectionResultProcessor<UIMetawidget>... inspectionResultProcessors)
public void setWidgetBuilder(WidgetBuilder<javax.faces.component.UIComponent,UIMetawidget> widgetBuilder)
public WidgetBuilder<javax.faces.component.UIComponent,UIMetawidget> getWidgetBuilder()
UIComponent.setBinding
.public void addWidgetProcessor(WidgetProcessor<javax.faces.component.UIComponent,UIMetawidget> widgetProcessor)
UIComponent.setBinding
.public void removeWidgetProcessor(WidgetProcessor<javax.faces.component.UIComponent,UIMetawidget> widgetProcessor)
UIComponent.setBinding
.public void setWidgetProcessors(WidgetProcessor<javax.faces.component.UIComponent,UIMetawidget>... widgetProcessors)
public List<WidgetProcessor<javax.faces.component.UIComponent,UIMetawidget>> getWidgetProcessors()
public <T> T getWidgetProcessor(Class<T> widgetProcessorClass)
public void setLayout(Layout<javax.faces.component.UIComponent,javax.faces.component.UIComponent,UIMetawidget> layout)
public Layout<javax.faces.component.UIComponent,javax.faces.component.UIComponent,UIMetawidget> getLayout()
public void setInspectFromParent(boolean inspectFromParent)
If the value binding is of the form #{foo.bar}
, sometimes
foo.getBar()
has useful metadata (such as UiLookup
). Metawidget
inspects from parent anyway if #{foo.bar}
evaluates to null
, but on
occasion it may be necessary to specify parent inspection explicitly.
The disadvantage of inspecting from parent (and the reason it is not enabled by default) is
that some Inspectors will not know the parent and so not be able to return anything. For
example, HibernateInspector only knows the Hibernate XML mapping files of persistent classes,
not the business class of a UI controller, so asking HibernateInspector to inspect
#{controller.current}
from its parent will always return null
.
public void setBuildWidgetsOnAjaxRequest(boolean buildWidgetsOnAjaxRequest)
UIMetawidget
does not rebuild widgets upon an AJAX request unless
the Metawidget's Id
is explicitly included in the list of execute
Ids. There are several reasons for this:
PreRenderViewEvent
(because it is the parent). But if X
rebuilds A and C, and they weren't part of the execute request, their values will be
lost. This is similar to how UIMetawidget
doesn't rebuild upon a validation
errorUIAutocomplete
) do not allow
fine-grained control over what is executed and rendered. They just execute and render
themselves
Although this default behaviour is safer it does, however, result in less dynamic UIs.
Clients can use setBuildWidgetsOnAjaxRequest
to override the default behaviour
and instruct UIMetawidget
to always rebuild widgets upon an AJAX request.
Mechanisms such as conversation-scoped backing beans can be used to avoid losing values.
public String getLabelString(Map<String,String> attributes)
The label is determined using the following algorithm:
UiLabel( "#{foo.name}'s name" )
public String getLocalizedKey(String key)
public void setParameter(String name, Object value)
This method will not override existing, manually specified <f:param />
.
Rather it will store the given parameter in UIComponent.getAttributes
. This has
several advantages:
getAttributes
Map, without needing to create nested UIParameter componentsremoveRecreatableChildren
because
although they are not manually specified, they will not be automatically recreated either
A disadvantage of this approach is that clients should always use
UIMetawidget.getParameter
to retrieve parameters, rather than searching for
UIParameter components directly.
public String getParameter(String name)
As discussed in the setParameter
JavaDoc, clients should use this method to
retrieve parameters, rather than searching for UIParameter components directly.
public void copyParameters(UIMetawidget copyFrom)
setParameter
JavaDoc, clients should use this method to
copy parameters, rather than creating UIParameter components directly.public void putClientProperty(Object key, Object value)
Unlike .setAttribute
, these values are not serialized by
ResponseStateManagerImpl
.
public <T> T getClientProperty(Object key)
Unlike .getAttribute
, these values are not serialized by
ResponseStateManagerImpl
.
public boolean isRendered()
isRendered
in class javax.faces.component.UIComponentBase
public void setRendererType(String rendererType)
This stops global defaults, if defined in metawidget.xml
, from overriding the
page-level renderType. This is because metawidget.xml
is not parsed until
after setRendererType has been called.
setRendererType
in class javax.faces.component.UIComponentBase
public void encodeBegin(javax.faces.context.FacesContext context) throws IOException
encodeBegin
in class javax.faces.component.UIComponentBase
IOException
public abstract String getComponentType()
Usually, clients will want to create a nested-Metawidget using the same subclass as
themselves. To be 'proper' in JSF, though, we should go via
application.createComponent
. Unfortunately by default a UIComponent does not
know its own component type, so subclasses must override this method.
This method is public for use by NestedLayoutDecorators.
public void initNestedMetawidget(UIMetawidget nestedMetawidget, Map<String,String> attributes)
public Object saveState(javax.faces.context.FacesContext context)
saveState
in interface javax.faces.component.StateHolder
saveState
in class javax.faces.component.UIInput
public void restoreState(javax.faces.context.FacesContext context, Object state)
restoreState
in interface javax.faces.component.StateHolder
restoreState
in class javax.faces.component.UIInput
protected UIMetawidget.Pipeline newPipeline()
Subclasses wishing to use their own Pipeline should override this method to instantiate their version.
protected void registerBuildWidgetsSupport()
Subclasses wishing to use their own mechanism should override this method to instantiate their version.
protected void buildWidgets() throws Exception
Subclasses can override this method as a common entry point regardless of whether PreRenderViewEventSupport (JSF2) or EncodeBeginSupport (JSF1) is being used.
Exception
protected abstract String getDefaultConfiguration()
protected void startBuild()
protected void layoutWidget(javax.faces.component.UIComponent component, String elementName, Map<String,String> attributes)
elementName
- XML node name of the business field. Typically 'entity', 'property' or 'action'.
Never nullprotected void endBuild()
Copyright © 2015. All Rights Reserved.