Package org.apache.myfaces.commons.exporter

Source Code of org.apache.myfaces.commons.exporter.FaceletsExporterActionListenerTag

/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements.  See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership.  The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License.  You may obtain a copy of the License at
*
*   http://www.apache.org/licenses/LICENSE-2.0
*
* 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.apache.myfaces.commons.exporter;

import java.io.IOException;

import javax.el.ELException;
import javax.el.ValueExpression;
import javax.faces.FacesException;
import javax.faces.component.ActionSource;
import javax.faces.component.UIComponent;
import javax.faces.view.facelets.ComponentHandler;
import javax.faces.view.facelets.FaceletContext;
import javax.faces.view.facelets.FaceletException;
import javax.faces.view.facelets.TagAttribute;
import javax.faces.view.facelets.TagConfig;
import javax.faces.view.facelets.TagHandler;

/**
* The (FaceletsExporterActionListenerTag) is responsible for handling the
* ExporterActionListener Tag in Facelets.
*/
public class FaceletsExporterActionListenerTag extends TagHandler
{

    private final TagAttribute _for;

    private final TagAttribute _fileType;

    private final TagAttribute _fileName;

    public FaceletsExporterActionListenerTag(TagConfig tagConfig)
    {
        super(tagConfig);
        this._for = getRequiredAttribute(ExporterActionListener.FOR_KEY);
        this._fileType = getRequiredAttribute(ExporterActionListener.FILE_TYPE_KEY);
        this._fileName = getRequiredAttribute(ExporterActionListener.FILENAME_KEY);
    }

    public void apply(FaceletContext faceletContext, UIComponent parent)
            throws IOException, FacesException, FaceletException, ELException
    {
        if (ComponentHandler.isNew(parent))
        {
            ValueExpression forVE = _for.getValueExpression(faceletContext,
                    Object.class);
            ValueExpression fileTypeVE = _fileType.getValueExpression(
                    faceletContext, Object.class);
            ValueExpression fileNameVE = _fileName.getValueExpression(
                    faceletContext, Object.class);

            ActionSource actionSource = (ActionSource) parent;
            actionSource.addActionListener(new ExporterActionListener(
                    (String) forVE.getValue(faceletContext),
                    (String) fileTypeVE.getValue(faceletContext),
                    (String) fileNameVE.getValue(faceletContext)));
        }
    }
}
TOP

Related Classes of org.apache.myfaces.commons.exporter.FaceletsExporterActionListenerTag

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.