org.metawidget.faces.component.html.widgetbuilder.HtmlLookupOutputText 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.faces.component.html.widgetbuilder;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import javax.faces.component.html.HtmlOutputText;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import org.metawidget.util.CollectionUtils;
import org.metawidget.widgetbuilder.iface.WidgetBuilderException;
/**
* Component to output text based on a lookup value.
*
* This is an internal API and is subject to change.
*
* @author Richard Kennard
*/
public class HtmlLookupOutputText
extends HtmlOutputText {
//
// Public statics
//
@SuppressWarnings( "hiding" )
public static final String COMPONENT_TYPE = "org.metawidget.HtmlLookupOutputText";
//
// Private members
//
private List mValues;
private List mLabels;
//
// Public methods
//
public void setLabels( List values, List labels ) {
mValues = values;
mLabels = labels;
if ( mValues.size() != mLabels.size() ) {
throw WidgetBuilderException.newException( "There are " + mValues.size() + " possible values, but " + mLabels.size() + " possible labels" );
}
}
@Override
public Object getValue() {
Object value = super.getValue();
if ( value == null ) {
return null;
}
// Special support for Collections
if ( value instanceof Collection> ) {
Collection> values = (Collection>) value;
if ( values.isEmpty() ) {
return null;
}
try {
boolean gotConverter = false;
Converter converter = null;
Collection