001/* 002 * (C) Copyright 2013 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.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; 018 019import java.io.IOException; 020 021import javax.faces.component.UIComponent; 022import javax.faces.component.html.HtmlForm; 023import javax.faces.context.FacesContext; 024 025import org.apache.commons.logging.Log; 026import org.apache.commons.logging.LogFactory; 027import org.nuxeo.runtime.api.Framework; 028 029/** 030 * Override the default form component to add warnings for nested forms issues when debug mode is on. 031 * 032 * @since 5.7 033 */ 034public class NXHtmlForm extends HtmlForm { 035 036 private static final Log log = LogFactory.getLog(NXHtmlForm.class); 037 038 @Override 039 public void encodeBegin(FacesContext context) throws IOException { 040 if (Framework.isDevModeSet()) { 041 // sanity check before checking for nested forms: issue an error if 042 // there is a parent container that is a form 043 UIComponent parent = getParent(); 044 while (parent != null) { 045 if (parent instanceof NXHtmlForm) { 046 log.error(String.format("Form component with id '%s' is already surrounded" 047 + " by a form with id '%s'", getId(), parent.getId())); 048 break; 049 } 050 parent = parent.getParent(); 051 } 052 } 053 super.processDecodes(context); 054 } 055 056}