001/*
002 * (C) Copyright 2017 Nuxeo (http://nuxeo.com/) and contributors.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl-2.1.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * Contributors:
015 *     Thomas Roger
016 */
017
018package org.nuxeo.ecm.platform.ui.web.component.html;
019
020
021import javax.el.ValueExpression;
022import javax.faces.component.html.HtmlInputText;
023import javax.faces.context.FacesContext;
024
025/**
026 * Overriding the default {@code HtmlInputText} to handle HTML5 attributes.
027 *
028 * @since 9.1
029 */
030public class NXHtmlInputText extends HtmlInputText {
031
032    public NXHtmlInputText() {
033        super();
034    }
035
036    private String placeholder;
037
038    public String getPlaceholder() {
039        if (null != this.placeholder) {
040            return this.placeholder;
041        }
042        ValueExpression _ve = getValueExpression("placeholder");
043        if (_ve != null) {
044            return (String) _ve.getValue(getFacesContext().getELContext());
045        } else {
046            return null;
047        }
048    }
049
050    public void setPlaceholder(String placeholder) {
051        this.placeholder = placeholder;
052    }
053
054    private Object[] _values;
055
056    @Override
057    public Object saveState(FacesContext _context) {
058        if (_values == null) {
059            _values = new Object[2];
060        }
061        _values[0] = super.saveState(_context);
062        _values[1] = placeholder;
063        return _values;
064    }
065
066    @Override
067    public void restoreState(FacesContext _context, Object _state) {
068        _values = (Object[]) _state;
069        super.restoreState(_context, _values[0]);
070        this.placeholder= (java.lang.String) _values[1];
071    }
072
073}