org.metawidget.inspectionresultprocessor.faces.FacesInspectionResultProcessorConfig Maven / Gradle / Ivy
// Metawidget
//
// This file is dual licensed under both the LGPL
// (http://www.gnu.org/licenses/lgpl-2.1.html) and the EPL
// (http://www.eclipse.org/org/documents/epl-v10.php). As a
// recipient of Metawidget, you may choose to receive it under either
// the LGPL or the EPL.
//
// Commercial licenses are also available. See http://metawidget.org
// for details.
package org.metawidget.inspectionresultprocessor.faces;
import static org.metawidget.inspector.faces.FacesInspectionResultConstants.*;
import org.metawidget.inspector.impl.propertystyle.PropertyStyle;
import org.metawidget.util.simple.ObjectUtils;
/**
* Configures a FacesInspectionResultProcessor prior to use. Once instantiated,
* InspectorResultProcessors are immutable.
*
* @author Richard Kennard
*/
public class FacesInspectionResultProcessorConfig {
//
// Private members
//
private PropertyStyle mInjectThis;
private String[] mIgnoreAttributes = new String[] { FACES_AJAX_ACTION, FACES_CONVERTER, FACES_EXPRESSION, FACES_LOOKUP, FACES_LOOKUP_ITEM_LABEL, FACES_LOOKUP_ITEM_VALUE, FACES_SUGGEST };
//
// Public methods
//
/**
* Sets the PropertyStyle to use to inject a request-level '_this' attribute (the underscore is
* needed because 'this' is a reserved word in EL) into JSF evaluations.
*
* JSF EL expressions rely on the JSF context being properly initialized with certain managed
* bean names. This is rather brittle. Instead, injecting '_this' allows the EL to refer to the
* originating object (i.e. #{_this.name}
) regardless of how the JSF context is
* configured.
*
* Note: injectThis
cannot be used within attributes such as
* faces-lookup
. Those attributes map to well-defined places within the JSF
* framework (i.e. f:selectItems
) and are evaluated at a different phase of the JSF
* lifecycle. In some cases they will skip invoking FacesInspectionResultProcessor
.
* For example if a h:selectOneMenu
fails to validate during POSTback, its
* f:selectItems
will be redisplayed without a new inspection and with no chance to
* injectThis
.
*
* @return this, as part of a fluent interface
*/
public FacesInspectionResultProcessorConfig setInjectThis( PropertyStyle injectThis ) {
mInjectThis = injectThis;
// Fluent interface
return this;
}
/**
* Sets the names of attributes to ignore. Some attributes, such as FACES_LOOKUP are
* expected to be EL expressions and should not be evaluated.
*
* @return this, as part of a fluent interface
*/
public FacesInspectionResultProcessorConfig setIgnoreAttributes( String... ignoreAttributes ) {
mIgnoreAttributes = ignoreAttributes;
// Fluent interface
return this;
}
@Override
public boolean equals( Object that ) {
if ( this == that ) {
return true;
}
if ( !ObjectUtils.nullSafeClassEquals( this, that ) ) {
return false;
}
if ( !ObjectUtils.nullSafeEquals( mInjectThis, ( (FacesInspectionResultProcessorConfig) that ).mInjectThis ) ) {
return false;
}
if ( !ObjectUtils.nullSafeEquals( mIgnoreAttributes, ( (FacesInspectionResultProcessorConfig) that ).mIgnoreAttributes ) ) {
return false;
}
return true;
}
@Override
public int hashCode() {
int hashCode = 1;
hashCode = 31 * hashCode + ObjectUtils.nullSafeHashCode( mInjectThis );
hashCode = 31 * hashCode + ObjectUtils.nullSafeHashCode( mIgnoreAttributes );
return hashCode;
}
//
// Protected methods
//
protected PropertyStyle getInjectThis() {
return mInjectThis;
}
protected String[] getIgnoreAttributes() {
return mIgnoreAttributes;
}
}