001/* 002 * (C) Copyright 2014 Nuxeo SA (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 * Anahide Tchertchian 016 */ 017package org.nuxeo.ecm.platform.ui.web.component.holder; 018 019import java.io.IOException; 020 021import javax.faces.component.UIComponent; 022import javax.faces.context.FacesContext; 023import javax.faces.context.ResponseWriter; 024import javax.faces.convert.ConverterException; 025 026import com.sun.faces.renderkit.RenderKitUtils; 027import com.sun.faces.renderkit.html_basic.HiddenRenderer; 028 029/** 030 * Extend hidden renderer to provide client behaviours (onchange events management). 031 * 032 * @since 6.0 033 */ 034public class ValueHolderRenderer extends HiddenRenderer { 035 036 @Override 037 public Object getConvertedValue(FacesContext context, UIComponent component, Object submittedValue) 038 throws ConverterException { 039 // make sure submitted value is converted to String first 040 String submitted = null; 041 if (submittedValue != null) { 042 submitted = submittedValue.toString(); 043 } 044 return super.getConvertedValue(context, component, submitted); 045 } 046 047 @Override 048 protected void getEndTextToRender(FacesContext context, UIComponent component, String currentValue) 049 throws IOException { 050 051 ResponseWriter writer = context.getResponseWriter(); 052 assert (writer != null); 053 054 writer.startElement("input", component); 055 writeIdAttributeIfNecessary(context, writer, component); 056 writer.writeAttribute("type", "hidden", "type"); 057 String clientId = component.getClientId(context); 058 writer.writeAttribute("name", clientId, "clientId"); 059 060 // render default text specified 061 if (currentValue != null) { 062 writer.writeAttribute("value", currentValue, "value"); 063 } 064 065 // Nuxeo patch 066 RenderKitUtils.renderOnchange(context, component, false); 067 068 writer.endElement("input"); 069 070 } 071 072}