001/* 002 * (C) Copyright 2006-2007 Nuxeo SAS (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 * <a href="mailto:at@nuxeo.com">Anahide Tchertchian</a> 016 * 017 * $Id: TextWidgetTypeHandler.java 30416 2008-02-21 19:10:37Z atchertchian $ 018 */ 019 020package org.nuxeo.ecm.platform.forms.layout.facelets.plugins; 021 022import javax.faces.component.html.HtmlInputHidden; 023import javax.faces.view.facelets.ComponentHandler; 024import javax.faces.view.facelets.CompositeFaceletHandler; 025import javax.faces.view.facelets.FaceletContext; 026import javax.faces.view.facelets.FaceletHandler; 027import javax.faces.view.facelets.TagAttribute; 028import javax.faces.view.facelets.TagAttributes; 029import javax.faces.view.facelets.TagConfig; 030 031import org.nuxeo.ecm.platform.forms.layout.api.BuiltinWidgetModes; 032import org.nuxeo.ecm.platform.forms.layout.api.Widget; 033import org.nuxeo.ecm.platform.forms.layout.api.exceptions.WidgetException; 034import org.nuxeo.ecm.platform.forms.layout.facelets.FaceletHandlerHelper; 035import org.nuxeo.ecm.platform.ui.web.component.seam.UIHtmlText; 036 037import com.sun.faces.facelets.tag.TagAttributesImpl; 038 039/** 040 * Hidden widget. 041 * 042 * @author <a href="mailto:cpriceputu@nuxeo.com">Cristian Priceputu</a> 043 */ 044public class HiddenWidgetTypeHandler extends AbstractWidgetTypeHandler { 045 046 private static final long serialVersionUID = 2202878489813240926L; 047 048 @Override 049 public FaceletHandler getFaceletHandler(FaceletContext ctx, TagConfig tagConfig, Widget widget, 050 FaceletHandler[] subHandlers) throws WidgetException { 051 FaceletHandlerHelper helper = new FaceletHandlerHelper(ctx, tagConfig); 052 String mode = widget.getMode(); 053 String widgetId = widget.getId(); 054 String widgetName = widget.getName(); 055 String widgetTagConfigId = widget.getTagConfigId(); 056 TagAttributes attributes; 057 if (BuiltinWidgetModes.isLikePlainMode(mode)) { 058 // use attributes without id 059 attributes = helper.getTagAttributes(widget); 060 } else { 061 attributes = helper.getTagAttributes(widgetId, widget); 062 } 063 FaceletHandler leaf = getNextHandler(ctx, tagConfig, widget, subHandlers, helper, false, false); 064 if (BuiltinWidgetModes.EDIT.equals(mode)) { 065 ComponentHandler input = helper.getHtmlComponentHandler(widgetTagConfigId, attributes, leaf, 066 HtmlInputHidden.COMPONENT_TYPE, null); 067 String msgId = helper.generateMessageId(widgetName); 068 ComponentHandler message = helper.getMessageComponentHandler(widgetTagConfigId, msgId, widgetId, null); 069 FaceletHandler[] handlers = { input, message }; 070 return new CompositeFaceletHandler(handlers); 071 } else { 072 // default on text for other modes 073 ComponentHandler output = helper.getHtmlComponentHandler(widgetTagConfigId, attributes, leaf, 074 HtmlInputHidden.COMPONENT_TYPE, null); 075 if (BuiltinWidgetModes.PDF.equals(mode)) { 076 // add a surrounding p:html tag handler 077 return helper.getHtmlComponentHandler(widgetTagConfigId, new TagAttributesImpl(new TagAttribute[0]), 078 output, UIHtmlText.class.getName(), null); 079 } else { 080 return output; 081 } 082 } 083 } 084}