001/* 002 * (C) Copyright 2013 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Anahide Tchertchian 018 */ 019package org.nuxeo.ecm.platform.ui.web.component; 020 021import java.io.IOException; 022 023import javax.faces.component.UIComponent; 024import javax.faces.component.html.HtmlForm; 025import javax.faces.context.FacesContext; 026 027import org.apache.commons.logging.Log; 028import org.apache.commons.logging.LogFactory; 029import org.nuxeo.runtime.api.Framework; 030 031/** 032 * Override the default form component to add warnings for nested forms issues when debug mode is on. 033 * 034 * @since 5.7 035 */ 036public class NXHtmlForm extends HtmlForm { 037 038 private static final Log log = LogFactory.getLog(NXHtmlForm.class); 039 040 @Override 041 public void encodeBegin(FacesContext context) throws IOException { 042 if (Framework.isDevModeSet()) { 043 // sanity check before checking for nested forms: issue an error if 044 // there is a parent container that is a form 045 UIComponent parent = getParent(); 046 while (parent != null) { 047 if (parent instanceof NXHtmlForm) { 048 log.error("Form component with id '" + getId() + "' is already surrounded by a form with id '" 049 + parent.getId() + "'"); 050 break; 051 } 052 parent = parent.getParent(); 053 } 054 } 055 super.processDecodes(context); 056 } 057 058}