001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.util.bridges.jsf.common;
016    
017    import com.liferay.portal.kernel.language.LanguageUtil;
018    import com.liferay.portal.kernel.util.StringPool;
019    
020    import java.util.ArrayList;
021    import java.util.Locale;
022    
023    import javax.faces.context.FacesContext;
024    import javax.faces.model.SelectItem;
025    
026    /**
027     * <p>
028     * This class provides a convenient way of building lists of JSF SelectItem
029     * objects, and convenience method for operating against them.
030     * </p>
031     *
032     * @author Neil Griffin
033     */
034    public class SelectItemList extends ArrayList<SelectItem> {
035    
036            public void prependEmptySelectItem(FacesContext facesContext) {
037                    Locale locale = facesContext.getExternalContext().getRequestLocale();
038    
039                    Object value = StringPool.BLANK;
040                    String label = LanguageUtil.get(locale, "select");
041    
042                    add(0, new SelectItem(value, label));
043            }
044    
045    }