org.metawidget.faces.component.html.widgetbuilder.HtmlLookupOutputText Maven / Gradle / Ivy
// Metawidget (licensed under LGPL)
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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