/* * (C) Copyright 2006-2007 Nuxeo SAS (http://nuxeo.com/) and contributors. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the GNU Lesser General Public License * (LGPL) version 2.1 which accompanies this distribution, and is available at * http://www.gnu.org/licenses/lgpl.html * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * Contributors: * <a href="mailto:at@nuxeo.com">Anahide Tchertchian</a> * * $Id: TestWidgetTypeHandler.java 28498 2008-01-05 11:46:25Z sfermigier $ */ package org.nuxeo.ecm.platform.layout.facelets; import javax.faces.component.html.HtmlInputText; import javax.faces.component.html.HtmlOutputText; import javax.faces.view.facelets.ComponentHandler; import javax.faces.view.facelets.CompositeFaceletHandler; import javax.faces.view.facelets.FaceletContext; import javax.faces.view.facelets.FaceletHandler; import javax.faces.view.facelets.TagAttributes; import javax.faces.view.facelets.TagConfig; import org.nuxeo.ecm.platform.forms.layout.api.BuiltinWidgetModes; import org.nuxeo.ecm.platform.forms.layout.api.Widget; import org.nuxeo.ecm.platform.forms.layout.api.exceptions.WidgetException; import org.nuxeo.ecm.platform.forms.layout.facelets.FaceletHandlerHelper; import org.nuxeo.ecm.platform.forms.layout.facelets.LeafFaceletHandler; import org.nuxeo.ecm.platform.forms.layout.facelets.plugins.AbstractWidgetTypeHandler; /** * Test widget that shows possibilities on how to write a widget tag handler. * * @author <a href="mailto:at@nuxeo.com">Anahide Tchertchian</a> */ public class DummyWidgetTypeHandler extends AbstractWidgetTypeHandler { private static final long serialVersionUID = 1495841177711755669L; @Override public FaceletHandler getFaceletHandler(FaceletContext ctx, TagConfig tagConfig, Widget widget, FaceletHandler[] subHandlers) throws WidgetException { FaceletHandlerHelper helper = new FaceletHandlerHelper(ctx, tagConfig); String mode = widget.getMode(); String widgetTagConfigId = widget.getTagConfigId(); FaceletHandler[] handlers = null; String originalId = helper.generateUniqueId(); TagAttributes attributes = helper.getTagAttributes(originalId, widget); FaceletHandler leaf = new LeafFaceletHandler(); if (BuiltinWidgetModes.VIEW.equals(mode)) { ComponentHandler output = helper.getHtmlComponentHandler( widgetTagConfigId, attributes, leaf, HtmlOutputText.COMPONENT_TYPE, null); handlers = new FaceletHandler[] { output }; } else if (BuiltinWidgetModes.EDIT.equals(mode)) { ComponentHandler input = helper.getHtmlComponentHandler( widgetTagConfigId, attributes, leaf, HtmlInputText.COMPONENT_TYPE, null); String msgId = helper.generateUniqueId(originalId); ComponentHandler message = helper.getMessageComponentHandler( widgetTagConfigId, msgId, originalId, "errorMessage"); handlers = new FaceletHandler[] { input, message }; } if (handlers == null) { return new LeafFaceletHandler(); } else { return new CompositeFaceletHandler(handlers); } } }