All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.ajax4jsf.tag.FacetHandler Maven / Gradle / Ivy

Go to download

Ajax4jsf is an open source extension to the JavaServer Faces standard that adds AJAX capability to JSF applications without requiring the writing of any JavaScript.

The newest version!
/**
 * Licensed under the Common Development and Distribution License,
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.sun.com/cddl/
 *   
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 
 * implied. See the License for the specific language governing
 * permissions and limitations under the License.
 */

package org.ajax4jsf.tag;

import java.io.IOException;

import javax.el.ELException;
import javax.faces.FacesException;
import javax.faces.component.UIComponent;
import javax.faces.component.UIComponentBase;

import org.ajax4jsf.framework.util.message.Messages;

import com.sun.facelets.FaceletContext;
import com.sun.facelets.FaceletException;
import com.sun.facelets.tag.TagAttribute;
import com.sun.facelets.tag.TagConfig;
import com.sun.facelets.tag.TagException;
import com.sun.facelets.tag.TagHandler;

/**
 * Register a named facet on the UIComponent associated with the closest parent
 * UIComponent custom action. 

See tag * documentation. * * @author Jacob Hookom * @version $Id: FacetHandler.java,v 1.4 2006/07/29 11:49:07 alexsmirnov Exp $ */ public final class FacetHandler extends TagHandler { /** * A UIComponent for capturing a child UIComponent, representative of the * desired Facet * * @author Jacob Hookom * */ private final static class UIFacet extends UIComponentBase { public String getFamily() { return null; } } protected final TagAttribute name; public FacetHandler(TagConfig config) { super(config); this.name = this.getRequiredAttribute("name"); } /* (non-Javadoc) * @see com.sun.facelets.FaceletHandler#apply(com.sun.facelets.FaceletContext, javax.faces.component.UIComponent) */ public void apply(FaceletContext ctx, UIComponent parent) throws IOException, FacesException, FaceletException, ELException { UIFacet facet = new UIFacet(); UIComponent c; // Check for existing facet String facetName = this.name.getValue(ctx); c = parent.getFacet(facetName); if (null != c) { parent.getFacets().remove(facetName); facet.getChildren().add(c); } this.nextHandler.apply(ctx, facet); int childCount = facet.getChildCount(); if (childCount == 1) { c = (UIComponent) facet.getChildren().get(0); parent.getFacets().put(facetName, c); } else { throw new TagException(this.tag, Messages.getMessage(Messages.FACET_TAG_MANY_CHILDREN_ERROR)); } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy