org.apache.myfaces.trinidad.component.UIXSubform 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 javax.faces.FacesException;
import javax.faces.component.ContextCallback;
import javax.faces.component.NamingContainer;
import javax.faces.context.FacesContext;
import javax.faces.event.FacesEvent;
import javax.faces.event.PhaseId;
import org.apache.myfaces.trinidad.bean.FacesBean;
import org.apache.myfaces.trinidad.bean.PropertyKey;
import org.apache.myfaces.trinidad.util.ComponentUtils;
/**
*
* UIXSubform is the base abstraction for an independently submittable
* region of a page. The contents of a subform will only be validated
* (or otherwise processed) if a component inside of the subform is
* responsible for submitting the page. This allows for comparatively
* fine-grained control of which components will be validated and pushed
* into the model without the compromises of using entirely separate form
* elements. UIXSubform is a NamingContainer and
* therefore IDs can be reused between subforms.
*
*
*
* A UIXSubform is considered "submitted" if an
* event is queued by one of its children or facets for a phase later
* than "Apply Request Values" (that is, for later than
* decode() ). The most common example is a
* (non-immediate) "command" component (like an <h:commandButton>
* or <tr:commandButton>).
*
*
* A UIXSubform will always allow the
* "Apply Request Values" phase to execute for its children,
* even when not "submitted", but when not "submitted", the
* "Process Validations" and "Update Model Values" phases will
* be skipped. This differs from an ordinary form component,
* which, when not submitted, does not (and cannot) run
* "Apply Request Values" either.
*
*
*
*
* In some scenarios, there may be buttons (or other components
* that submit the page) outside of the main content of a page. If
* this main content is in a UIXSubform, it could not be fully
* processed whenever those buttons are clicked, since those
* buttons aren't inside of the UIXSubform. To support this
* scenario, Apache Trinidad supports a "default" property on
* UIXSubform. A "default" subform behaves like any other
* subform in most respects, but if no subforms
* are "submitted" - if no subform has an appropriate event
* come from its children - then all "default" subforms act
* as if they are "submitted".
*
*
*
* 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 UIXSubform extends UIXComponentBase
implements NamingContainer
{
static public final FacesBean.Type TYPE = new FacesBean.Type(
UIXComponentBase.TYPE);
static public final PropertyKey DEFAULT_KEY =
TYPE.registerKey("default", Boolean.class, Boolean.FALSE, PropertyKey.CAP_NOT_BOUND);
static public final String COMPONENT_FAMILY =
"org.apache.myfaces.trinidad.Subform";
static public final String COMPONENT_TYPE =
"org.apache.myfaces.trinidad.Subform";
/**
* Construct an instance of the UIXSubform.
*/
public UIXSubform()
{
super("org.apache.myfaces.trinidad.Subform");
}
@Override
public void queueEvent(FacesEvent event)
{
// If the event is being queued for anything *after* APPLY_REQUEST_VALUES,
// then this subform is active.
if (PhaseId.APPLY_REQUEST_VALUES.compareTo(event.getPhaseId()) < 0)
{
_storeSomethingSubmitted(FacesContext.getCurrentInstance());
setSubmitted(true);
}
super.queueEvent(event);
}
@Override
public void processDecodes(FacesContext context)
{
setSubmitted(false);
super.processDecodes(context);
}
@Override
public void processValidators(FacesContext context)
{
boolean submitted = isSubmitted();
if (!submitted && isDefault() && !_isSomethingSubmitted(context))
{
submitted = true;
setSubmitted(true);
}
if (submitted)
super.processValidators(context);
}
@Override
public void processUpdates(FacesContext context)
{
if (isSubmitted())
super.processUpdates(context);
}
@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);
}
@SuppressWarnings("unchecked")
static private void _storeSomethingSubmitted(FacesContext context)
{
context.getExternalContext().getRequestMap().put(_SOMETHING_SUBMITTED,
Boolean.TRUE);
}
static private boolean _isSomethingSubmitted(FacesContext context)
{
return Boolean.TRUE.equals(context.getExternalContext().
getRequestMap().get(_SOMETHING_SUBMITTED));
}
/**
* Sets whether the subform was submitted on this request
*
* @param submitted the new submitted value
*/
final public void setSubmitted(boolean submitted)
{
String clientId = getClientId();
FacesContext.getCurrentInstance().getExternalContext().getRequestMap().put(
_SUBMITTED_PREFIX + clientId,
submitted ? Boolean.TRUE : Boolean.FALSE);
}
/**
* Gets whether the subform was submitted on this request
*
* @return the new submitted value
*/
final public boolean isSubmitted()
{
String clientId = getClientId();
Object submitted = FacesContext.getCurrentInstance().getExternalContext().getRequestMap().get(
_SUBMITTED_PREFIX + clientId);
return ComponentUtils.resolveBoolean(submitted, false);
}
static private final String _SOMETHING_SUBMITTED =
"org.apache.myfaces.trinidad.component.UIXSubformSubmitted";
static private final String _SUBMITTED_PREFIX =
"org.apache.myfaces.trinidad.component.UIXSubform.";
/**
* @deprecated submitted is request scope, and therefore will not be saved on the faces bean as a property
*/
@Deprecated
static public final PropertyKey SUBMITTED_KEY =
TYPE.registerKey("submitted", Boolean.class, Boolean.FALSE, PropertyKey.CAP_NOT_BOUND | PropertyKey.CAP_TRANSIENT);
/**
* Gets whether the subform should assume it
* has been submitted. When set to "true", "submitted" will be
* considered true if no other subform has been submitted.
*
* @return the new default value
*/
final public boolean isDefault()
{
return ComponentUtils.resolveBoolean(getProperty(DEFAULT_KEY), false);
}
/**
* Sets whether the subform should assume it
* has been submitted. When set to "true", "submitted" will be
* considered true if no other subform has been submitted.
*
* @param defaultParam the new default value
*/
final public void setDefault(boolean defaultParam)
{
setProperty(DEFAULT_KEY, defaultParam ? Boolean.TRUE : Boolean.FALSE);
}
@Override
public String getFamily()
{
return COMPONENT_FAMILY;
}
@Override
protected FacesBean.Type getBeanType()
{
return TYPE;
}
/**
* Construct an instance of the UIXSubform.
*/
protected UIXSubform(
String rendererType
)
{
super(rendererType);
}
static
{
TYPE.lockAndRegister("org.apache.myfaces.trinidad.Subform","org.apache.myfaces.trinidad.Subform");
}
}